libmicrohttpd

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

commit 9b340996a4da7d2ee3e31788da4e913e7115b073
parent 2056b9d360ab5724db56b31d7aef74e5ec5ed80d
Author: Heikki Lindholm <holin@iki.fi>
Date:   Thu, 26 Mar 2009 13:04:49 +0000

attempt to fix a threading issue on OS X: close() in MHD_stop_daemon will get
stuck if someone's in accept(), but select() in MHD_select may get stuck if
the socket isn't already closed on shutdown.


Diffstat:
Msrc/daemon/daemon.c | 23++++++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c @@ -1423,13 +1423,6 @@ MHD_stop_daemon (struct MHD_Daemon *daemon) daemon->worker_pool[i].socket_fd = -1; } -#if DEBUG_CLOSE -#if HAVE_MESSAGES - MHD_DLOG (daemon, "MHD shutdown, closing listen socket\n"); -#endif -#endif - CLOSE (fd); - /* Signal workers to stop and clean them up */ for (i = 0; i < daemon->worker_pool_size; ++i) pthread_kill (daemon->worker_pool[i].pid, SIGALRM); @@ -1444,11 +1437,27 @@ MHD_stop_daemon (struct MHD_Daemon *daemon) ((0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)) && (0 == daemon->worker_pool_size))) { +#if DEBUG_CLOSE +#if HAVE_MESSAGES + MHD_DLOG (daemon, "MHD shutdown, closing listen socket\n"); +#endif +#endif + CLOSE (fd); pthread_kill (daemon->pid, SIGALRM); pthread_join (daemon->pid, &unused); } MHD_close_connections (daemon); + if (0 < daemon->worker_pool_size) + { +#if DEBUG_CLOSE +#if HAVE_MESSAGES + MHD_DLOG (daemon, "MHD shutdown, closing listen socket\n"); +#endif +#endif + CLOSE (fd); + } + /* TLS clean up */ #if HTTPS_SUPPORT if (daemon->options & MHD_USE_SSL)