aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2020-10-21 11:35:22 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2020-10-21 11:37:56 +0300
commitadcdafc558640b4ef4c22e43c198fe382df33836 (patch)
tree760f893af9b2e6e403fb031305e4219247c85809
parent4b18c05142f821fb6b1ba7e8841fce9b623ad9e3 (diff)
downloadlibmicrohttpd-adcdafc558640b4ef4c22e43c198fe382df33836.tar.gz
libmicrohttpd-adcdafc558640b4ef4c22e43c198fe382df33836.zip
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.
-rw-r--r--src/microhttpd/daemon.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 710ba55b..b18885f0 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -6018,7 +6018,7 @@ MHD_start_daemon_va (unsigned int flags,
6018#ifdef HAVE_LISTEN_SHUTDOWN 6018#ifdef HAVE_LISTEN_SHUTDOWN
6019 if (0 != (*pflags & MHD_USE_NO_LISTEN_SOCKET)) 6019 if (0 != (*pflags & MHD_USE_NO_LISTEN_SOCKET))
6020#endif 6020#endif
6021 *pflags |= MHD_USE_ITC; /* yes, must use ITC to signal thread */ 6021 *pflags |= MHD_USE_ITC; /* yes, must use ITC to signal thread */
6022 } 6022 }
6023#ifdef DAUTH_SUPPORT 6023#ifdef DAUTH_SUPPORT
6024 daemon->digest_auth_rand_size = 0; 6024 daemon->digest_auth_rand_size = 0;
@@ -6594,10 +6594,21 @@ MHD_start_daemon_va (unsigned int flags,
6594 } 6594 }
6595#endif /* HTTPS_SUPPORT */ 6595#endif /* HTTPS_SUPPORT */
6596#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 6596#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6597 if ( (0 != (*pflags & MHD_USE_INTERNAL_POLLING_THREAD)) && 6597 /* Start threads if requested by parameters */
6598 ( (0 == (*pflags & MHD_USE_NO_LISTEN_SOCKET)) || 6598 if (0 != (*pflags & MHD_USE_INTERNAL_POLLING_THREAD))
6599 (MHD_ITC_IS_VALID_ (daemon->itc)) ) )
6600 { 6599 {
6600 /* Internal thread (or threads) is used.
6601 * Make sure that MHD will be able to communicate with threads. */
6602 /* If using a thread pool ITC will be initialised later
6603 * for each individual worker thread. */
6604#ifdef HAVE_LISTEN_SHUTDOWN
6605 mhd_assert ((1 < daemon->worker_pool_size) || \
6606 (MHD_ITC_IS_VALID_ (daemon->itc)) || \
6607 (MHD_INVALID_SOCKET != daemon->listen_fd));
6608#else /* ! HAVE_LISTEN_SHUTDOWN */
6609 mhd_assert ((1 < daemon->worker_pool_size) || \
6610 (MHD_ITC_IS_VALID_ (daemon->itc)));
6611#endif /* ! HAVE_LISTEN_SHUTDOWN */
6601 if (0 == daemon->worker_pool_size) 6612 if (0 == daemon->worker_pool_size)
6602 { 6613 {
6603 if (! MHD_create_named_thread_ (&daemon->pid, 6614 if (! MHD_create_named_thread_ (&daemon->pid,
@@ -6630,6 +6641,7 @@ MHD_start_daemon_va (unsigned int flags,
6630 unsigned int leftover_conns = daemon->connection_limit 6641 unsigned int leftover_conns = daemon->connection_limit
6631 % daemon->worker_pool_size; 6642 % daemon->worker_pool_size;
6632 6643
6644 mhd_assert (2 <= daemon->worker_pool_size);
6633 i = 0; /* we need this in case fcntl or malloc fails */ 6645 i = 0; /* we need this in case fcntl or malloc fails */
6634 6646
6635 /* Allocate memory for pooled objects */ 6647 /* Allocate memory for pooled objects */
@@ -6680,6 +6692,13 @@ MHD_start_daemon_va (unsigned int flags,
6680 else 6692 else
6681 MHD_itc_set_invalid_ (d->itc); 6693 MHD_itc_set_invalid_ (d->itc);
6682 6694
6695#ifdef HAVE_LISTEN_SHUTDOWN
6696 mhd_assert ((MHD_ITC_IS_VALID_ (d->itc)) || \
6697 (MHD_INVALID_SOCKET != d->listen_fd));
6698#else /* ! HAVE_LISTEN_SHUTDOWN */
6699 mhd_assert (MHD_ITC_IS_VALID_ (d->itc));
6700#endif /* ! HAVE_LISTEN_SHUTDOWN */
6701
6683 /* Divide available connections evenly amongst the threads. 6702 /* Divide available connections evenly amongst the threads.
6684 * Thread indexes in [0, leftover_conns) each get one of the 6703 * Thread indexes in [0, leftover_conns) each get one of the
6685 * leftover connections. */ 6704 * leftover connections. */