libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 32d09c83915ca7cab0890cdc246fc3bd63a2a97b
parent b3903cffea8d3b4fda1a41ce9fa36f23bdfa68fa
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Sat, 23 Apr 2016 16:15:58 +0000

MHD_quiesce_daemon(): notify other threads so listen socket FD
is removed from awaiting select() and poll().

Diffstat:
MChangeLog | 4++++
Msrc/microhttpd/daemon.c | 19++++++++++++++++---
2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,7 @@ +Sat Apr 23 15:39:38 CET 2016 + Notify other threads in MHD_quiesce_daemon() so listen socket FD + is removed from awaiting select() and poll(). -EG + Sat Apr 23 14:17:15 CET 2016 Revert "shutdown trigger select" on Darwin. Fixed daemon shutdown on Darwin without "MHD_USE_PIPE_FOR_SHUTDOWN" option. -EG diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c @@ -3105,9 +3105,9 @@ MHD_start_daemon (unsigned int flags, * clients to continue processing, but stops accepting new * connections. Note that the caller is responsible for closing the * returned socket; however, if MHD is run using threads (anything but - * external select mode), it must not be closed until AFTER - * #MHD_stop_daemon has been called (as it is theoretically possible - * that an existing thread is still using it). + * external select mode), socket will be removed from existing threads + * with some delay and it must not be closed while it's in use. To make + * sure that socket is not used anymore, call #MHD_stop_daemon. * * Note that some thread modes require the caller to have passed * #MHD_USE_PIPE_FOR_SHUTDOWN when using this API. If this daemon is @@ -3154,7 +3154,13 @@ MHD_quiesce_daemon (struct MHD_Daemon *daemon) MHD_PANIC ("Failed to remove listen FD from epoll set\n"); daemon->worker_pool[i].listen_socket_in_epoll = MHD_NO; } + else #endif + if (MHD_INVALID_PIPE_ != daemon->worker_pool[i].wpipe[1]) + { + if (1 != MHD_pipe_write_ (daemon->worker_pool[i].wpipe[1], "q", 1)) + MHD_PANIC ("failed to signal quiesce via pipe"); + } } daemon->socket_fd = MHD_INVALID_SOCKET; #if EPOLL_SUPPORT @@ -3169,7 +3175,14 @@ MHD_quiesce_daemon (struct MHD_Daemon *daemon) MHD_PANIC ("Failed to remove listen FD from epoll set\n"); daemon->listen_socket_in_epoll = MHD_NO; } + else #endif + if (MHD_INVALID_PIPE_ != daemon->wpipe[1]) + { + if (1 != MHD_pipe_write_ (daemon->wpipe[1], "q", 1)) + MHD_PANIC ("failed to signal quiesce via pipe"); + } + return ret; }