gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libmicrohttpd] 04/05: Added flag for non-blocking listen socket


From: gnunet
Subject: [libmicrohttpd] 04/05: Added flag for non-blocking listen socket
Date: Tue, 24 Aug 2021 15:18:00 +0200

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a commit to branch master
in repository libmicrohttpd.

commit c556824313ee9d038935645b8926debc5306ad43
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Tue Aug 24 15:58:46 2021 +0300

    Added flag for non-blocking listen socket
---
 src/microhttpd/daemon.c   | 59 ++++++++++++++++++++++++++---------------------
 src/microhttpd/internal.h |  5 ++++
 2 files changed, 38 insertions(+), 26 deletions(-)

diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index ce14a944..231ac57f 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -6954,42 +6954,49 @@ MHD_start_daemon_va (unsigned int flags,
     }
   }
 #endif /* HAVE_GETSOCKNAME */
-  if ( (MHD_INVALID_SOCKET != listen_fd) &&
-       (! MHD_socket_nonblocking_ (listen_fd)) )
+
+  if (MHD_INVALID_SOCKET != listen_fd)
   {
+    if (! MHD_socket_nonblocking_ (listen_fd))
+    {
 #ifdef HAVE_MESSAGES
-    MHD_DLOG (daemon,
-              _ ("Failed to set nonblocking mode on listening socket: %s\n"),
-              MHD_socket_last_strerr_ ());
+      MHD_DLOG (daemon,
+                _ ("Failed to set nonblocking mode on listening socket: %s\n"),
+                MHD_socket_last_strerr_ ());
 #endif
-    if (0 != (*pflags & MHD_USE_EPOLL)
+      if (0 != (*pflags & MHD_USE_EPOLL)
 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
-        || (daemon->worker_pool_size > 0)
+          || (daemon->worker_pool_size > 0)
 #endif
-        )
+          )
+      {
+        /* Accept must be non-blocking. Multiple children may wake up
+         * to handle a new connection, but only one will win the race.
+         * The others must immediately return. */
+        MHD_socket_close_chk_ (listen_fd);
+        goto free_and_fail;
+      }
+      daemon->listen_nonblk = false;
+    }
+    else
+      daemon->listen_nonblk = true;
+    if ( (! MHD_SCKT_FD_FITS_FDSET_ (listen_fd,
+                                     NULL)) &&
+         (0 == (*pflags & (MHD_USE_POLL | MHD_USE_EPOLL)) ) )
     {
-      /* Accept must be non-blocking. Multiple children may wake up
-       * to handle a new connection, but only one will win the race.
-       * The others must immediately return. */
+#ifdef HAVE_MESSAGES
+      MHD_DLOG (daemon,
+                _ ("Listen socket descriptor (%d) is not " \
+                   "less than FD_SETSIZE (%d).\n"),
+                (int) listen_fd,
+                (int) FD_SETSIZE);
+#endif
       MHD_socket_close_chk_ (listen_fd);
       goto free_and_fail;
     }
   }
-  if ( (MHD_INVALID_SOCKET != listen_fd) &&
-       (! MHD_SCKT_FD_FITS_FDSET_ (listen_fd,
-                                   NULL)) &&
-       (0 == (*pflags & (MHD_USE_POLL | MHD_USE_EPOLL)) ) )
-  {
-#ifdef HAVE_MESSAGES
-    MHD_DLOG (daemon,
-              _ ("Listen socket descriptor (%d) is not " \
-                 "less than FD_SETSIZE (%d).\n"),
-              (int) listen_fd,
-              (int) FD_SETSIZE);
-#endif
-    MHD_socket_close_chk_ (listen_fd);
-    goto free_and_fail;
-  }
+  else
+    daemon->listen_nonblk = false; /* Actually listen socket does not exist */
 
 #ifdef EPOLL_SUPPORT
   if ( (0 != (*pflags & MHD_USE_EPOLL))
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index 5154dc38..9db32af1 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -1827,6 +1827,11 @@ struct MHD_Daemon
    */
   MHD_socket listen_fd;
 
+  /**
+   * Listen socket is non-blocking.
+   */
+  bool listen_nonblk;
+
 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
   /**
    * Worker daemons (one per thread)

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]