aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/daemon.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/daemon.c')
-rw-r--r--src/microhttpd/daemon.c55
1 files changed, 2 insertions, 53 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index cdd6aae6..7a8aa4ac 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -3414,52 +3414,6 @@ parse_options_va (struct MHD_Daemon *daemon,
3414} 3414}
3415 3415
3416 3416
3417/**
3418 * Create a listen socket, if possible with SOCK_CLOEXEC flag set.
3419 *
3420 * @param daemon daemon for which we create the socket
3421 * @param domain socket domain (i.e. PF_INET)
3422 * @param type socket type (usually SOCK_STREAM)
3423 * @param protocol desired protocol, 0 for default
3424 */
3425static MHD_socket
3426create_listen_socket (struct MHD_Daemon *daemon,
3427 int domain, int type, int protocol)
3428{
3429 MHD_socket fd;
3430 int cloexec_set;
3431#if defined(OSX) && defined(SOL_SOCKET) && defined(SO_NOSIGPIPE)
3432 static const int on_val = 1;
3433#endif
3434
3435 /* use SOCK_STREAM rather than ai_socktype: some getaddrinfo
3436 * implementations do not set ai_socktype, e.g. RHL6.2. */
3437#if defined(MHD_POSIX_SOCKETS) && defined(SOCK_CLOEXEC)
3438 fd = socket (domain, type | SOCK_CLOEXEC, protocol);
3439 cloexec_set = MHD_YES;
3440#elif defined(MHD_WINSOCK_SOCKETS) && defined (WSA_FLAG_NO_HANDLE_INHERIT)
3441 fd = WSASocketW (domain, type, protocol, NULL, 0, WSA_FLAG_NO_HANDLE_INHERIT);
3442 cloexec_set = MHD_YES;
3443#else /* !SOCK_CLOEXEC */
3444 fd = socket (domain, type, protocol);
3445 cloexec_set = MHD_NO;
3446#endif /* !SOCK_CLOEXEC */
3447 if ( (MHD_INVALID_SOCKET == fd) && (MHD_NO != cloexec_set) )
3448 {
3449 fd = socket (domain, type, protocol);
3450 cloexec_set = MHD_NO;
3451 }
3452 if (MHD_INVALID_SOCKET == fd)
3453 return MHD_INVALID_SOCKET;
3454#if defined(OSX) && defined(SOL_SOCKET) && defined(SO_NOSIGPIPE)
3455 setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &on_val, sizeof(on_val));
3456#endif
3457 if (MHD_NO == cloexec_set)
3458 MHD_socket_noninheritable_ (fd);
3459 return fd;
3460}
3461
3462
3463#if EPOLL_SUPPORT 3417#if EPOLL_SUPPORT
3464/** 3418/**
3465 * Setup epoll() FD for the daemon and initialize it to listen 3419 * Setup epoll() FD for the daemon and initialize it to listen
@@ -3797,17 +3751,12 @@ MHD_start_daemon_va (unsigned int flags,
3797 (0 == (daemon->options & MHD_USE_NO_LISTEN_SOCKET)) ) 3751 (0 == (daemon->options & MHD_USE_NO_LISTEN_SOCKET)) )
3798 { 3752 {
3799 /* try to open listen socket */ 3753 /* try to open listen socket */
3800 if (0 != (flags & MHD_USE_IPv6)) 3754 socket_fd = MHD_socket_create_listen_(flags & MHD_USE_IPv6);
3801 socket_fd = create_listen_socket (daemon,
3802 PF_INET6, SOCK_STREAM, 0);
3803 else
3804 socket_fd = create_listen_socket (daemon,
3805 PF_INET, SOCK_STREAM, 0);
3806 if (MHD_INVALID_SOCKET == socket_fd) 3755 if (MHD_INVALID_SOCKET == socket_fd)
3807 { 3756 {
3808#ifdef HAVE_MESSAGES 3757#ifdef HAVE_MESSAGES
3809 MHD_DLOG (daemon, 3758 MHD_DLOG (daemon,
3810 "Call to socket failed: %s\n", 3759 "Failed to create socket for listening: %s\n",
3811 MHD_socket_last_strerr_ ()); 3760 MHD_socket_last_strerr_ ());
3812#endif 3761#endif
3813 goto free_and_fail; 3762 goto free_and_fail;