]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib/tsocket: split out tsocket_bsd_error() from tsocket_bsd_pending()
authorStefan Metzmacher <metze@samba.org>
Thu, 13 Oct 2022 08:39:59 +0000 (10:39 +0200)
committerStefan Metzmacher <metze@samba.org>
Wed, 19 Oct 2022 16:14:36 +0000 (16:14 +0000)
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>
lib/tsocket/tsocket_bsd.c

index 5650763d1e6f4767f334219dd3af4d3daf65e6f8..a4c2d0cf336b3cce6b5ef855e69226e5ca28033b 100644 (file)
@@ -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;