[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [libmicrohttpd] 05/05: Added support for SOCK_NOSIGPIPE fro
From: |
gnunet |
Subject: |
[GNUnet-SVN] [libmicrohttpd] 05/05: Added support for SOCK_NOSIGPIPE from Solaris 11.4 and NetBSD 7+ |
Date: |
Sun, 02 Jun 2019 18:20:50 +0200 |
This is an automated email from the git hooks/post-receive script.
karlson2k pushed a commit to branch master
in repository libmicrohttpd.
commit 1f7962830e0a72a6d7a85ae61ab95341ad0b8fdd
Author: Evgeny Grin (Karlson2k) <address@hidden>
AuthorDate: Sun Jun 2 01:52:11 2019 +0300
Added support for SOCK_NOSIGPIPE from Solaris 11.4 and NetBSD 7+
---
src/microhttpd/daemon.c | 2 +-
src/microhttpd/mhd_sockets.c | 25 ++++++++++++++++++++-----
src/microhttpd/mhd_sockets.h | 8 +++++++-
3 files changed, 28 insertions(+), 7 deletions(-)
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index a5051c01..0764f286 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -3136,7 +3136,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
s = accept4 (fd,
addr,
&addrlen,
- MAYBE_SOCK_CLOEXEC | MAYBE_SOCK_NONBLOCK);
+ MAYBE_SOCK_CLOEXEC | MAYBE_SOCK_NONBLOCK |
MAYBE_SOCK_NOSIGPIPE);
sk_nonbl = (MAYBE_SOCK_NONBLOCK != 0);
#else /* ! USE_ACCEPT4 */
s = accept (fd,
diff --git a/src/microhttpd/mhd_sockets.c b/src/microhttpd/mhd_sockets.c
index 3504dc26..04405945 100644
--- a/src/microhttpd/mhd_sockets.c
+++ b/src/microhttpd/mhd_sockets.c
@@ -507,12 +507,18 @@ MHD_socket_create_listen_ (int pf)
{
MHD_socket fd;
int cloexec_set;
+#if defined(SOCK_NOSIGPIPE) || defined(MHD_socket_nosignal_)
+ int nosigpipe_set;
+#endif /* SOCK_NOSIGPIPE || MHD_socket_nosignal_ */
-#if defined(MHD_POSIX_SOCKETS) && defined(SOCK_CLOEXEC)
+#if defined(MHD_POSIX_SOCKETS) && ( defined(SOCK_CLOEXEC) ||
defined(SOCK_NOSIGPIPE) )
fd = socket (pf,
- SOCK_STREAM | SOCK_CLOEXEC,
+ SOCK_STREAM | SOCK_CLOEXEC | MAYBE_SOCK_NOSIGPIPE,
0);
- cloexec_set = !0;
+ cloexec_set = (MAYBE_SOCK_CLOEXEC != 0);
+#if defined(SOCK_NOSIGPIPE) || defined(MHD_socket_nosignal_)
+ nosigpipe_set = (MAYBE_SOCK_NOSIGPIPE != 0);
+#endif /* SOCK_NOSIGPIPE || MHD_socket_nosignal_ */
#elif defined(MHD_WINSOCK_SOCKETS) && defined (WSA_FLAG_NO_HANDLE_INHERIT)
fd = WSASocketW (pf,
SOCK_STREAM,
@@ -533,15 +539,24 @@ MHD_socket_create_listen_ (int pf)
}
if (MHD_INVALID_SOCKET == fd)
return MHD_INVALID_SOCKET;
+
+#if defined(SOCK_NOSIGPIPE) || defined(MHD_socket_nosignal_)
+ if ( ( (! nosigpipe_set)
#ifdef MHD_socket_nosignal_
- if(! MHD_socket_nosignal_(fd))
+ || (! MHD_socket_nosignal_(fd))
+#endif /* MHD_socket_nosignal_ */
+ ) && (0 == MAYBE_MSG_NOSIGNAL) )
{
+ /* SIGPIPE disable is possible on this platform
+ * (so application expect that it will be disabled),
+ * but failed to be disabled here and it is not
+ * possible to disable SIGPIPE by MSG_NOSIGNAL. */
const int err = MHD_socket_get_error_ ();
(void) MHD_socket_close_ (fd);
MHD_socket_fset_error_ (err);
return MHD_INVALID_SOCKET;
}
-#endif /* MHD_socket_nosignal_ */
+#endif /* SOCK_NOSIGPIPE || MHD_socket_nosignal_ */
if (! cloexec_set)
(void) MHD_socket_noninheritable_ (fd);
diff --git a/src/microhttpd/mhd_sockets.h b/src/microhttpd/mhd_sockets.h
index 8663edd3..62ea46d5 100644
--- a/src/microhttpd/mhd_sockets.h
+++ b/src/microhttpd/mhd_sockets.h
@@ -162,6 +162,12 @@
# define MAYBE_SOCK_NONBLOCK 0
#endif /* ! HAVE_SOCK_NONBLOCK */
+#ifdef SOCK_NOSIGPIPE
+# define MAYBE_SOCK_NOSIGPIPE SOCK_NOSIGPIPE
+#else /* ! HAVE_SOCK_NONBLOCK */
+# define MAYBE_SOCK_NOSIGPIPE 0
+#endif /* ! HAVE_SOCK_NONBLOCK */
+
#ifdef MSG_NOSIGNAL
# define MAYBE_MSG_NOSIGNAL MSG_NOSIGNAL
#else /* ! MSG_NOSIGNAL */
@@ -178,7 +184,7 @@
# define SHUT_RDWR SD_BOTH
#endif
-#if HAVE_ACCEPT4+0 != 0 && (defined(HAVE_SOCK_NONBLOCK) ||
defined(SOCK_CLOEXEC))
+#if HAVE_ACCEPT4+0 != 0 && (defined(HAVE_SOCK_NONBLOCK) ||
defined(SOCK_CLOEXEC) || defined(SOCK_NOSIGPIPE))
# define USE_ACCEPT4 1
#endif
--
To stop receiving notification emails like this one, please contact
address@hidden
- [GNUnet-SVN] [libmicrohttpd] branch master updated (2a59d367 -> 1f796283), gnunet, 2019/06/02
- [GNUnet-SVN] [libmicrohttpd] 03/05: Properly handle port detection if AF_UNIX socket is used on *BSD, macOS, gnunet, 2019/06/02
- [GNUnet-SVN] [libmicrohttpd] 05/05: Added support for SOCK_NOSIGPIPE from Solaris 11.4 and NetBSD 7+,
gnunet <=
- [GNUnet-SVN] [libmicrohttpd] 02/05: Added .gitattributes, fixed line endings in ac_define_dir.m4, updated ac_define_dir.m4 to new version., gnunet, 2019/06/02
- [GNUnet-SVN] [libmicrohttpd] 04/05: configure: check for 'rand' and 'random' by MHD_CHECK_FUNC, gnunet, 2019/06/02
- [GNUnet-SVN] [libmicrohttpd] 01/05: configure: fixed detection of 'getsockname' on some systems (W32 x32), do not use 'getsockname()' if it is not detected by configure., gnunet, 2019/06/02