mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
lib/tsocket: split out tsocket_bsd_error() from tsocket_bsd_pending()
This will be used on its own soon.
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15202
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
(cherry picked from commit 9950efd83e
)
This commit is contained in:
parent
c805ccba33
commit
119bf60998
@ -171,11 +171,31 @@ static ssize_t tsocket_bsd_netlink_pending(int fd)
|
||||
}
|
||||
#endif
|
||||
|
||||
static ssize_t tsocket_bsd_error(int fd)
|
||||
{
|
||||
int ret, error = 0;
|
||||
socklen_t len = sizeof(error);
|
||||
|
||||
/*
|
||||
* if no data is available check if the socket is in error state. For
|
||||
* dgram sockets it's the way to return ICMP error messages of
|
||||
* connected sockets to the caller.
|
||||
*/
|
||||
ret = getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len);
|
||||
if (ret == -1) {
|
||||
return ret;
|
||||
}
|
||||
if (error != 0) {
|
||||
errno = error;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t tsocket_bsd_pending(int fd)
|
||||
{
|
||||
int ret, error;
|
||||
int ret;
|
||||
int value = 0;
|
||||
socklen_t len;
|
||||
|
||||
ret = ioctl(fd, FIONREAD, &value);
|
||||
if (ret == -1) {
|
||||
@ -192,23 +212,7 @@ static ssize_t tsocket_bsd_pending(int fd)
|
||||
return value;
|
||||
}
|
||||
|
||||
error = 0;
|
||||
len = sizeof(error);
|
||||
|
||||
/*
|
||||
* if no data is available check if the socket is in error state. For
|
||||
* dgram sockets it's the way to return ICMP error messages of
|
||||
* connected sockets to the caller.
|
||||
*/
|
||||
ret = getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len);
|
||||
if (ret == -1) {
|
||||
return ret;
|
||||
}
|
||||
if (error != 0) {
|
||||
errno = error;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
return tsocket_bsd_error(fd);
|
||||
}
|
||||
|
||||
static const struct tsocket_address_ops tsocket_address_bsd_ops;
|
||||
|
Loading…
Reference in New Issue
Block a user