[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libmicrohttpd] 05/05: Inherit non-blocking status when accepting on mos
From: |
gnunet |
Subject: |
[libmicrohttpd] 05/05: Inherit non-blocking status when accepting on most platforms |
Date: |
Tue, 24 Aug 2021 15:18:01 +0200 |
This is an automated email from the git hooks/post-receive script.
karlson2k pushed a commit to branch master
in repository libmicrohttpd.
commit 8361a3a7b73680bfe5dbc368be875368541ff20c
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Tue Aug 24 16:03:55 2021 +0300
Inherit non-blocking status when accepting on most platforms
When accept() is used, socket non-blocking flag is inherited from listen
socket almost on all platforms (except Linux kernel).
Actually modern platforms use accept4() so this change is mostly for W32.
---
src/microhttpd/daemon.c | 12 +++++++++---
src/microhttpd/mhd_sockets.h | 6 ++++++
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 231ac57f..c0278246 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -3550,7 +3550,11 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
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 */
@@ -3615,15 +3619,17 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
}
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"),
MHD_socket_last_strerr_ ());
-#endif
+#else /* ! HAVE_MESSAGES */
+ (void) 0; /* Mute compiler warning */
+#endif /* ! HAVE_MESSAGES */
}
else
sk_nonbl = true;
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.