gnunet-svn
[Top][All Lists]
Advanced

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

[libmicrohttpd] branch master updated (6621c055 -> 8361a3a7)


From: gnunet
Subject: [libmicrohttpd] branch master updated (6621c055 -> 8361a3a7)
Date: Tue, 24 Aug 2021 15:17:56 +0200

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

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from 6621c055 mhd_assert: added check for both _DEBUG and NDEBUG defined
     new 7a2a93b4 Fixed typo in 6621c055572524f5f247cd200ff7291c161f8b87
     new 3420745f MHD_accept_connection: cosmetics
     new 4371815f MHD_accept_connection: refactoring to improve readability
     new c5568243 Added flag for non-blocking listen socket
     new 8361a3a7 Inherit non-blocking status when accepting on most platforms

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/microhttpd/daemon.c      | 108 +++++++++++++++++++++++++------------------
 src/microhttpd/internal.h    |   5 ++
 src/microhttpd/mhd_assert.h  |   4 +-
 src/microhttpd/mhd_sockets.h |   6 +++
 4 files changed, 77 insertions(+), 46 deletions(-)

diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index a375152f..c0278246 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -3519,6 +3519,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
   MHD_socket fd;
   bool sk_nonbl;
   bool sk_spipe_supprs;
+  bool sk_cloexec;
 
 #ifdef MHD_USE_THREADS
   mhd_assert ( (0 == (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)) || \
@@ -3544,16 +3545,22 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
 #else  /* MHD_WINSOCK_SOCKETS */
   sk_spipe_supprs = true; /* Nothing to suppress on W32 */
 #endif /* MHD_WINSOCK_SOCKETS */
+  sk_cloexec = (SOCK_CLOEXEC_OR_ZERO != 0);
 #else  /* ! USE_ACCEPT4 */
   s = accept (fd,
               addr,
               &addrlen);
+#ifdef MHD_ACCEPT_INHERIT_NONBLOCK
+  sk_nonbl = daemon->listen_nonblk;
+#else  /* ! MHD_ACCEPT_INHERIT_NONBLOCK */
   sk_nonbl = false;
+#endif /* ! MHD_ACCEPT_INHERIT_NONBLOCK */
 #ifndef MHD_WINSOCK_SOCKETS
   sk_spipe_supprs = false;
 #else  /* MHD_WINSOCK_SOCKETS */
   sk_spipe_supprs = true; /* Nothing to suppress on W32 */
 #endif /* MHD_WINSOCK_SOCKETS */
+  sk_cloexec = false;
 #endif /* ! USE_ACCEPT4 */
   if ( (MHD_INVALID_SOCKET == s) ||
        (addrlen <= 0) )
@@ -3586,8 +3593,10 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
            would ever be cleared.  Instead trying to produce
            bit fat ugly warning. */
         MHD_DLOG (daemon,
-                  _ (
-                    "Hit process or system resource limit at FIRST connection. 
This is really bad as there is no sane way to proceed. Will try busy waiting 
for system resources to become magically available.\n"));
+                  _ ("Hit process or system resource limit at FIRST " \
+                     "connection. This is really bad as there is no sane " \
+                     "way to proceed. Will try busy waiting for system " \
+                     "resources to become magically available.\n"));
 #endif
       }
       else
@@ -3601,44 +3610,48 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
 #endif
 #ifdef HAVE_MESSAGES
         MHD_DLOG (daemon,
-                  _ (
-                    "Hit process or system resource limit at %u connections, 
temporarily suspending accept(). Consider setting a lower 
MHD_OPTION_CONNECTION_LIMIT.\n"),
+                  _ ("Hit process or system resource limit at %u " \
+                     "connections, temporarily suspending accept(). " \
+                     "Consider setting a lower 
MHD_OPTION_CONNECTION_LIMIT.\n"),
                   (unsigned int) daemon->connections);
 #endif
       }
     }
     return MHD_NO;
   }
-#if ! defined(USE_ACCEPT4) || ! defined(HAVE_SOCK_NONBLOCK)
-  if (! MHD_socket_nonblocking_ (s))
+
+  if (! sk_nonbl && ! MHD_socket_nonblocking_ (s))
   {
 #ifdef HAVE_MESSAGES
     MHD_DLOG (daemon,
-              _ (
-                "Failed to set nonblocking mode on incoming connection socket: 
%s\n"),
+              _ ("Failed to set nonblocking mode on incoming connection " \
+                 "socket: %s\n"),
               MHD_socket_last_strerr_ ());
-#endif
+#else  /* ! HAVE_MESSAGES */
+    (void) 0; /* Mute compiler warning */
+#endif /* ! HAVE_MESSAGES */
   }
   else
     sk_nonbl = true;
-#endif /* !USE_ACCEPT4 || !HAVE_SOCK_NONBLOCK */
-#if ! defined(USE_ACCEPT4) || ! defined(SOCK_CLOEXEC)
-  if (! MHD_socket_noninheritable_ (s))
+
+  if (! sk_cloexec && ! MHD_socket_noninheritable_ (s))
   {
 #ifdef HAVE_MESSAGES
     MHD_DLOG (daemon,
-              _ (
-                "Failed to set noninheritable mode on incoming connection 
socket.\n"));
-#endif
+              _ ("Failed to set noninheritable mode on incoming connection " \
+                 "socket.\n"));
+#else  /* ! HAVE_MESSAGES */
+    (void) 0; /* Mute compiler warning */
+#endif /* ! HAVE_MESSAGES */
   }
-#endif /* !USE_ACCEPT4 || !SOCK_CLOEXEC */
+
 #if defined(MHD_socket_nosignal_)
   if (! sk_spipe_supprs && ! MHD_socket_nosignal_ (s))
   {
 #ifdef HAVE_MESSAGES
     MHD_DLOG (daemon,
-              _ (
-                "Failed to suppress SIGPIPE on incoming connection socket: 
%s\n"),
+              _ ("Failed to suppress SIGPIPE on incoming connection " \
+                 "socket: %s\n"),
               MHD_socket_last_strerr_ ());
 #else  /* ! HAVE_MESSAGES */
     (void) 0; /* Mute compiler warning */
@@ -6947,42 +6960,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)
diff --git a/src/microhttpd/mhd_assert.h b/src/microhttpd/mhd_assert.h
index 6113646f..f74eca51 100644
--- a/src/microhttpd/mhd_assert.h
+++ b/src/microhttpd/mhd_assert.h
@@ -31,10 +31,10 @@
 
 #include "mhd_options.h"
 
-#if ! deifned(_DEBUG) && ! defined(NDEBUG)
+#if ! defined(_DEBUG) && ! defined(NDEBUG)
 #define NDEBUG 1 /* Use NDEBUG by default */
 #endif /* !_DEBUG && !NDEBUG */
-#if deifned(_DEBUG) && defined(NDEBUG)
+#if defined(_DEBUG) && defined(NDEBUG)
 #error Both _DEBUG and NDEBUG are defined
 #endif /* _DEBUG && NDEBUG */
 #ifdef NDEBUG
diff --git a/src/microhttpd/mhd_sockets.h b/src/microhttpd/mhd_sockets.h
index 56ea64db..18f831a9 100644
--- a/src/microhttpd/mhd_sockets.h
+++ b/src/microhttpd/mhd_sockets.h
@@ -199,6 +199,12 @@ typedef SOCKET MHD_socket;
 #  define USE_ACCEPT4 1
 #endif
 
+#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || \
+  defined(MHD_WINSOCK_SOCKETS) || defined(__MACH__) || defined(__sun)
+/* Most of OSes inherit nonblocking setting from the listen socket */
+#define MHD_ACCEPT_INHERIT_NONBLOCK 1
+#endif
+
 #if defined(HAVE_EPOLL_CREATE1) && defined(EPOLL_CLOEXEC)
 #  define USE_EPOLL_CREATE1 1
 #endif /* HAVE_EPOLL_CREATE1 && EPOLL_CLOEXEC */

-- 
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]