libmicrohttpd

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

commit adcdafc558640b4ef4c22e43c198fe382df33836
parent 4b18c05142f821fb6b1ba7e8841fce9b623ad9e3
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Wed, 21 Oct 2020 11:35:22 +0300

Fixed non-functional daemon with NO_LISTEN and thread pool.
MHD failed to start any threads is used with MHD_USE_NO_LISTEN_SOCKET and
with thread pool.

Diffstat:
Msrc/microhttpd/daemon.c | 27+++++++++++++++++++++++----
1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c @@ -6018,7 +6018,7 @@ MHD_start_daemon_va (unsigned int flags, #ifdef HAVE_LISTEN_SHUTDOWN if (0 != (*pflags & MHD_USE_NO_LISTEN_SOCKET)) #endif - *pflags |= MHD_USE_ITC; /* yes, must use ITC to signal thread */ + *pflags |= MHD_USE_ITC; /* yes, must use ITC to signal thread */ } #ifdef DAUTH_SUPPORT daemon->digest_auth_rand_size = 0; @@ -6594,10 +6594,21 @@ MHD_start_daemon_va (unsigned int flags, } #endif /* HTTPS_SUPPORT */ #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) - if ( (0 != (*pflags & MHD_USE_INTERNAL_POLLING_THREAD)) && - ( (0 == (*pflags & MHD_USE_NO_LISTEN_SOCKET)) || - (MHD_ITC_IS_VALID_ (daemon->itc)) ) ) + /* Start threads if requested by parameters */ + if (0 != (*pflags & MHD_USE_INTERNAL_POLLING_THREAD)) { + /* Internal thread (or threads) is used. + * Make sure that MHD will be able to communicate with threads. */ + /* If using a thread pool ITC will be initialised later + * for each individual worker thread. */ +#ifdef HAVE_LISTEN_SHUTDOWN + mhd_assert ((1 < daemon->worker_pool_size) || \ + (MHD_ITC_IS_VALID_ (daemon->itc)) || \ + (MHD_INVALID_SOCKET != daemon->listen_fd)); +#else /* ! HAVE_LISTEN_SHUTDOWN */ + mhd_assert ((1 < daemon->worker_pool_size) || \ + (MHD_ITC_IS_VALID_ (daemon->itc))); +#endif /* ! HAVE_LISTEN_SHUTDOWN */ if (0 == daemon->worker_pool_size) { if (! MHD_create_named_thread_ (&daemon->pid, @@ -6630,6 +6641,7 @@ MHD_start_daemon_va (unsigned int flags, unsigned int leftover_conns = daemon->connection_limit % daemon->worker_pool_size; + mhd_assert (2 <= daemon->worker_pool_size); i = 0; /* we need this in case fcntl or malloc fails */ /* Allocate memory for pooled objects */ @@ -6680,6 +6692,13 @@ MHD_start_daemon_va (unsigned int flags, else MHD_itc_set_invalid_ (d->itc); +#ifdef HAVE_LISTEN_SHUTDOWN + mhd_assert ((MHD_ITC_IS_VALID_ (d->itc)) || \ + (MHD_INVALID_SOCKET != d->listen_fd)); +#else /* ! HAVE_LISTEN_SHUTDOWN */ + mhd_assert (MHD_ITC_IS_VALID_ (d->itc)); +#endif /* ! HAVE_LISTEN_SHUTDOWN */ + /* Divide available connections evenly amongst the threads. * Thread indexes in [0, leftover_conns) each get one of the * leftover connections. */