aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2019-06-02 01:52:11 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2019-06-02 01:57:31 +0300
commit1f7962830e0a72a6d7a85ae61ab95341ad0b8fdd (patch)
tree46659d48592a639aeca730a5b29d31b09087e9d3
parenta58870f63a661211d45b393779ef3ed1dab2e3b8 (diff)
downloadlibmicrohttpd-1f7962830e0a72a6d7a85ae61ab95341ad0b8fdd.tar.gz
libmicrohttpd-1f7962830e0a72a6d7a85ae61ab95341ad0b8fdd.zip
Added support for SOCK_NOSIGPIPE from Solaris 11.4 and NetBSD 7+
-rw-r--r--src/microhttpd/daemon.c2
-rw-r--r--src/microhttpd/mhd_sockets.c25
-rw-r--r--src/microhttpd/mhd_sockets.h8
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)
3136 s = accept4 (fd, 3136 s = accept4 (fd,
3137 addr, 3137 addr,
3138 &addrlen, 3138 &addrlen,
3139 MAYBE_SOCK_CLOEXEC | MAYBE_SOCK_NONBLOCK); 3139 MAYBE_SOCK_CLOEXEC | MAYBE_SOCK_NONBLOCK | MAYBE_SOCK_NOSIGPIPE);
3140 sk_nonbl = (MAYBE_SOCK_NONBLOCK != 0); 3140 sk_nonbl = (MAYBE_SOCK_NONBLOCK != 0);
3141#else /* ! USE_ACCEPT4 */ 3141#else /* ! USE_ACCEPT4 */
3142 s = accept (fd, 3142 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)
507{ 507{
508 MHD_socket fd; 508 MHD_socket fd;
509 int cloexec_set; 509 int cloexec_set;
510#if defined(SOCK_NOSIGPIPE) || defined(MHD_socket_nosignal_)
511 int nosigpipe_set;
512#endif /* SOCK_NOSIGPIPE || MHD_socket_nosignal_ */
510 513
511#if defined(MHD_POSIX_SOCKETS) && defined(SOCK_CLOEXEC) 514#if defined(MHD_POSIX_SOCKETS) && ( defined(SOCK_CLOEXEC) || defined(SOCK_NOSIGPIPE) )
512 fd = socket (pf, 515 fd = socket (pf,
513 SOCK_STREAM | SOCK_CLOEXEC, 516 SOCK_STREAM | SOCK_CLOEXEC | MAYBE_SOCK_NOSIGPIPE,
514 0); 517 0);
515 cloexec_set = !0; 518 cloexec_set = (MAYBE_SOCK_CLOEXEC != 0);
519#if defined(SOCK_NOSIGPIPE) || defined(MHD_socket_nosignal_)
520 nosigpipe_set = (MAYBE_SOCK_NOSIGPIPE != 0);
521#endif /* SOCK_NOSIGPIPE || MHD_socket_nosignal_ */
516#elif defined(MHD_WINSOCK_SOCKETS) && defined (WSA_FLAG_NO_HANDLE_INHERIT) 522#elif defined(MHD_WINSOCK_SOCKETS) && defined (WSA_FLAG_NO_HANDLE_INHERIT)
517 fd = WSASocketW (pf, 523 fd = WSASocketW (pf,
518 SOCK_STREAM, 524 SOCK_STREAM,
@@ -533,15 +539,24 @@ MHD_socket_create_listen_ (int pf)
533 } 539 }
534 if (MHD_INVALID_SOCKET == fd) 540 if (MHD_INVALID_SOCKET == fd)
535 return MHD_INVALID_SOCKET; 541 return MHD_INVALID_SOCKET;
542
543#if defined(SOCK_NOSIGPIPE) || defined(MHD_socket_nosignal_)
544 if ( ( (! nosigpipe_set)
536#ifdef MHD_socket_nosignal_ 545#ifdef MHD_socket_nosignal_
537 if(! MHD_socket_nosignal_(fd)) 546 || (! MHD_socket_nosignal_(fd))
547#endif /* MHD_socket_nosignal_ */
548 ) && (0 == MAYBE_MSG_NOSIGNAL) )
538 { 549 {
550 /* SIGPIPE disable is possible on this platform
551 * (so application expect that it will be disabled),
552 * but failed to be disabled here and it is not
553 * possible to disable SIGPIPE by MSG_NOSIGNAL. */
539 const int err = MHD_socket_get_error_ (); 554 const int err = MHD_socket_get_error_ ();
540 (void) MHD_socket_close_ (fd); 555 (void) MHD_socket_close_ (fd);
541 MHD_socket_fset_error_ (err); 556 MHD_socket_fset_error_ (err);
542 return MHD_INVALID_SOCKET; 557 return MHD_INVALID_SOCKET;
543 } 558 }
544#endif /* MHD_socket_nosignal_ */ 559#endif /* SOCK_NOSIGPIPE || MHD_socket_nosignal_ */
545 if (! cloexec_set) 560 if (! cloexec_set)
546 (void) MHD_socket_noninheritable_ (fd); 561 (void) MHD_socket_noninheritable_ (fd);
547 562
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 @@
162# define MAYBE_SOCK_NONBLOCK 0 162# define MAYBE_SOCK_NONBLOCK 0
163#endif /* ! HAVE_SOCK_NONBLOCK */ 163#endif /* ! HAVE_SOCK_NONBLOCK */
164 164
165#ifdef SOCK_NOSIGPIPE
166# define MAYBE_SOCK_NOSIGPIPE SOCK_NOSIGPIPE
167#else /* ! HAVE_SOCK_NONBLOCK */
168# define MAYBE_SOCK_NOSIGPIPE 0
169#endif /* ! HAVE_SOCK_NONBLOCK */
170
165#ifdef MSG_NOSIGNAL 171#ifdef MSG_NOSIGNAL
166# define MAYBE_MSG_NOSIGNAL MSG_NOSIGNAL 172# define MAYBE_MSG_NOSIGNAL MSG_NOSIGNAL
167#else /* ! MSG_NOSIGNAL */ 173#else /* ! MSG_NOSIGNAL */
@@ -178,7 +184,7 @@
178# define SHUT_RDWR SD_BOTH 184# define SHUT_RDWR SD_BOTH
179#endif 185#endif
180 186
181#if HAVE_ACCEPT4+0 != 0 && (defined(HAVE_SOCK_NONBLOCK) || defined(SOCK_CLOEXEC)) 187#if HAVE_ACCEPT4+0 != 0 && (defined(HAVE_SOCK_NONBLOCK) || defined(SOCK_CLOEXEC) || defined(SOCK_NOSIGPIPE))
182# define USE_ACCEPT4 1 188# define USE_ACCEPT4 1
183#endif 189#endif
184 190