unix_msg: add flag to prepare_socket_nonblock()
authorRalph Boehme <slow@samba.org>
Mon, 22 Aug 2016 12:02:43 +0000 (14:02 +0200)
committerJeremy Allison <jra@samba.org>
Mon, 12 Sep 2016 22:19:26 +0000 (00:19 +0200)
This allows prepare_socket_nonblock() to be called to set a socket to
non-blocking (as before) as well as blocking. This will be used in a
subsequent commit.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/lib/unix_msg/unix_msg.c

index 17047ae9b094462eb0ad14f054dcbdb01605a15b..f86822e1a10b8a9d722f94b1c70e7d84e5f8672c 100644 (file)
@@ -80,7 +80,7 @@ static void unix_dgram_recv_handler(struct poll_watch *w, int fd, short events,
                                    void *private_data);
 
 /* Set socket non blocking. */
-static int prepare_socket_nonblock(int sock)
+static int prepare_socket_nonblock(int sock, bool nonblock)
 {
        int flags;
 #ifdef O_NONBLOCK
@@ -97,7 +97,11 @@ static int prepare_socket_nonblock(int sock)
        if (flags == -1) {
                return errno;
        }
-       flags |= FLAG_TO_SET;
+       if (nonblock) {
+               flags |= FLAG_TO_SET;
+       } else {
+               flags &= ~FLAG_TO_SET;
+       }
        if (fcntl(sock, F_SETFL, flags) == -1) {
                return errno;
        }
@@ -127,7 +131,7 @@ static int prepare_socket_cloexec(int sock)
 /* Set socket non blocking and close on exec. */
 static int prepare_socket(int sock)
 {
-       int ret = prepare_socket_nonblock(sock);
+       int ret = prepare_socket_nonblock(sock, true);
 
        if (ret) {
                return ret;