diff options
author | Stefan Metzmacher <metze@samba.org> | 2022-10-13 10:39:59 +0200 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2022-10-19 16:14:36 +0000 |
commit | 9950efd83e1a4b5e711f1d36fefa8a5d5e8b2410 (patch) | |
tree | dbc15f4c18bbee2ab52a5907d45eefd3fde1126e /lib/tsocket | |
parent | f0fb8b9508346aed50528216fd959a9b1a941409 (diff) | |
download | samba-9950efd83e1a4b5e711f1d36fefa8a5d5e8b2410.tar.gz |
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>
Diffstat (limited to 'lib/tsocket')
-rw-r--r-- | lib/tsocket/tsocket_bsd.c | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/lib/tsocket/tsocket_bsd.c b/lib/tsocket/tsocket_bsd.c index 5650763d1e6..a4c2d0cf336 100644 --- a/lib/tsocket/tsocket_bsd.c +++ b/lib/tsocket/tsocket_bsd.c @@ -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; |