gnunet-svn
[Top][All Lists]
Advanced

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

[libmicrohttpd] 09/29: daemon: added debug member to avoid accept4() usa


From: gnunet
Subject: [libmicrohttpd] 09/29: daemon: added debug member to avoid accept4() usage
Date: Tue, 20 Jun 2023 22:24:22 +0200

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

karlson2k pushed a commit to branch master
in repository libmicrohttpd.

commit 4b8fb0700b8671d1d92100285632e2671703c0f5
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Fri Oct 14 15:42:08 2022 +0300

    daemon: added debug member to avoid accept4() usage
---
 src/microhttpd/daemon.c   | 40 ++++++++++++++++++++++++++--------------
 src/microhttpd/internal.h | 12 ++++++++++++
 2 files changed, 38 insertions(+), 14 deletions(-)

diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 37df86d1..f9ffb388 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -3662,6 +3662,13 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
   bool sk_spipe_supprs;
   bool sk_cloexec;
   enum MHD_tristate sk_non_ip;
+#if defined(_DEBUG) && defined (USE_ACCEPT4)
+  const bool use_accept4 = ! daemon->avoid_accept4;
+#elif defined (USE_ACCEPT4)
+  static const bool use_accept4 = true;
+#else  /* ! USE_ACCEPT4 && ! _DEBUG */
+  static const bool use_accept4 = false;
+#endif /* ! USE_ACCEPT4 && ! _DEBUG */
 
 #ifdef MHD_USE_THREADS
   mhd_assert ( (0 == (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)) || \
@@ -3685,14 +3692,16 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
   sk_nonbl = false;
   sk_spipe_supprs = false;
   sk_cloexec = false;
+  s = MHD_INVALID_SOCKET;
 
 #ifdef USE_ACCEPT4
-  if (MHD_INVALID_SOCKET !=
-      (s = accept4 (fd,
-                    (struct sockaddr *) &addrstorage,
-                    &addrlen,
-                    SOCK_CLOEXEC_OR_ZERO | SOCK_NONBLOCK_OR_ZERO
-                    | SOCK_NOSIGPIPE_OR_ZERO)))
+  if (use_accept4 &&
+      (MHD_INVALID_SOCKET !=
+       (s = accept4 (fd,
+                     (struct sockaddr *) &addrstorage,
+                     &addrlen,
+                     SOCK_CLOEXEC_OR_ZERO | SOCK_NONBLOCK_OR_ZERO
+                     | SOCK_NOSIGPIPE_OR_ZERO))))
   {
     sk_nonbl = (SOCK_NONBLOCK_OR_ZERO != 0);
 #ifndef MHD_WINSOCK_SOCKETS
@@ -3702,11 +3711,13 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
 #endif /* MHD_WINSOCK_SOCKETS */
     sk_cloexec = (SOCK_CLOEXEC_OR_ZERO != 0);
   }
-#else  /* ! USE_ACCEPT4 */
-  if (MHD_INVALID_SOCKET !=
-      (s = accept (fd,
-                   (struct sockaddr *) &addrstorage,
-                   &addrlen)))
+#endif /* USE_ACCEPT4 */
+#if defined(_DEBUG) || ! defined(USE_ACCEPT4)
+  if (! use_accept4 &&
+      (MHD_INVALID_SOCKET !=
+       (s = accept (fd,
+                    (struct sockaddr *) &addrstorage,
+                    &addrlen))))
   {
 #ifdef MHD_ACCEPT_INHERIT_NONBLOCK
     sk_nonbl = daemon->listen_nonblk;
@@ -3720,7 +3731,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
 #endif /* MHD_WINSOCK_SOCKETS */
     sk_cloexec = false;
   }
-#endif /* ! USE_ACCEPT4 */
+#endif /* _DEBUG || !USE_ACCEPT4 */
 
   if (MHD_INVALID_SOCKET == s)
   {
@@ -3778,8 +3789,6 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
   sk_non_ip = daemon->listen_is_unix;
   if (0 >= addrlen)
   {
-    /* Should not happen as 'sockaddr_storage' must be large enough to
-     * store any address supported by the system. */
 #ifdef HAVE_MESSAGES
     if (_MHD_NO != daemon->listen_is_unix)
       MHD_DLOG (daemon,
@@ -7156,6 +7165,9 @@ MHD_start_daemon_va (unsigned int flags,
   /* There is no SIGPIPE on W32, nothing to block. */
   daemon->sigpipe_blocked = true;
 #endif /* _WIN32 && ! __CYGWIN__ */
+#if defined(_DEBUG) && defined(HAVE_ACCEPT4)
+  daemon->avoid_accept4 = false;
+#endif /* _DEBUG */
 
   if ( (0 != (*pflags & MHD_USE_THREAD_PER_CONNECTION)) &&
        (0 == (*pflags & MHD_USE_INTERNAL_POLLING_THREAD)) )
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index 0ea0953e..651e6170 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -2416,6 +2416,18 @@ struct MHD_Daemon
    * The value to be returned by #MHD_get_daemon_info()
    */
   union MHD_DaemonInfo daemon_info_dummy_port;
+
+#if defined(_DEBUG) && defined(HAVE_ACCEPT4)
+  /**
+   * If set to 'true', accept() function will be used instead of accept4() even
+   * if accept4() is available.
+   * This is a workaround for zzuf, which does not support sockets created
+   * by accept4() function.
+   * There is no API to change the value of this member, it can be flipped
+   * only by direct access to the struct member.
+   */
+  bool avoid_accept4;
+#endif /* _DEBUG */
 };
 
 

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