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.c64
1 files changed, 31 insertions, 33 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 9843866d..a53ba0d5 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -1333,7 +1333,7 @@ call_handlers (struct MHD_Connection *con,
1333 * TLS read-ready connection in 'read info' state as connection 1333 * TLS read-ready connection in 'read info' state as connection
1334 * without space in read buffer will be marked as 'info block'. */ 1334 * without space in read buffer will be marked as 'info block'. */
1335 if ( (! con->daemon->data_already_pending) && 1335 if ( (! con->daemon->data_already_pending) &&
1336 (0 == (con->daemon->options & MHD_USE_THREAD_PER_CONNECTION)) ) 1336 (! MHD_D_IS_USING_THREAD_PER_CONN_ (con->daemon)) )
1337 { 1337 {
1338 if (0 != (MHD_EVENT_LOOP_INFO_PROCESS & con->event_loop_info)) 1338 if (0 != (MHD_EVENT_LOOP_INFO_PROCESS & con->event_loop_info))
1339 con->daemon->data_already_pending = true; 1339 con->daemon->data_already_pending = true;
@@ -1708,7 +1708,7 @@ process_urh (struct MHD_UpgradeResponseHandle *urh)
1708 * and incoming forward buffer have some space. */ 1708 * and incoming forward buffer have some space. */
1709 if ( (connection->tls_read_ready) && 1709 if ( (connection->tls_read_ready) &&
1710 (urh->in_buffer_used < urh->in_buffer_size) && 1710 (urh->in_buffer_used < urh->in_buffer_size) &&
1711 (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) ) 1711 (! MHD_D_IS_USING_THREAD_PER_CONN_ (daemon)) )
1712 daemon->data_already_pending = true; 1712 daemon->data_already_pending = true;
1713 1713
1714 if ( (daemon->shutdown) && 1714 if ( (daemon->shutdown) &&
@@ -2875,7 +2875,7 @@ new_connection_process_ (struct MHD_Daemon *daemon,
2875 DLL_insert (daemon->connections_head, 2875 DLL_insert (daemon->connections_head,
2876 daemon->connections_tail, 2876 daemon->connections_tail,
2877 connection); 2877 connection);
2878 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 2878 if (! MHD_D_IS_USING_THREAD_PER_CONN_ (daemon))
2879 { 2879 {
2880 XDLL_insert (daemon->normal_timeout_head, 2880 XDLL_insert (daemon->normal_timeout_head,
2881 daemon->normal_timeout_tail, 2881 daemon->normal_timeout_tail,
@@ -2891,7 +2891,7 @@ new_connection_process_ (struct MHD_Daemon *daemon,
2891 &connection->socket_context, 2891 &connection->socket_context,
2892 MHD_CONNECTION_NOTIFY_STARTED); 2892 MHD_CONNECTION_NOTIFY_STARTED);
2893#ifdef MHD_USE_THREADS 2893#ifdef MHD_USE_THREADS
2894 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 2894 if (MHD_D_IS_USING_THREAD_PER_CONN_ (daemon))
2895 { 2895 {
2896 mhd_assert (! MHD_D_IS_USING_EPOLL_ (daemon)); 2896 mhd_assert (! MHD_D_IS_USING_EPOLL_ (daemon));
2897 if (! MHD_create_named_thread_ (&connection->tid, 2897 if (! MHD_create_named_thread_ (&connection->tid,
@@ -2978,7 +2978,7 @@ new_connection_process_ (struct MHD_Daemon *daemon,
2978 &connection->socket_context, 2978 &connection->socket_context,
2979 MHD_CONNECTION_NOTIFY_CLOSED); 2979 MHD_CONNECTION_NOTIFY_CLOSED);
2980 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); 2980 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
2981 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 2981 if (! MHD_D_IS_USING_THREAD_PER_CONN_ (daemon))
2982 { 2982 {
2983 XDLL_remove (daemon->normal_timeout_head, 2983 XDLL_remove (daemon->normal_timeout_head,
2984 daemon->normal_timeout_tail, 2984 daemon->normal_timeout_tail,
@@ -3189,7 +3189,7 @@ internal_suspend_connection_ (struct MHD_Connection *connection)
3189 3189
3190#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 3190#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3191 mhd_assert ( (! MHD_D_IS_USING_THREADS_ (daemon)) || \ 3191 mhd_assert ( (! MHD_D_IS_USING_THREADS_ (daemon)) || \
3192 (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) || \ 3192 MHD_D_IS_USING_THREAD_PER_CONN_ (daemon) || \
3193 MHD_thread_handle_ID_is_current_thread_ (daemon->tid) ); 3193 MHD_thread_handle_ID_is_current_thread_ (daemon->tid) );
3194 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); 3194 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
3195#endif 3195#endif
@@ -3202,7 +3202,7 @@ internal_suspend_connection_ (struct MHD_Connection *connection)
3202#endif 3202#endif
3203 return; 3203 return;
3204 } 3204 }
3205 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 3205 if (! MHD_D_IS_USING_THREAD_PER_CONN_ (daemon))
3206 { 3206 {
3207 if (connection->connection_timeout_ms == daemon->connection_timeout_ms) 3207 if (connection->connection_timeout_ms == daemon->connection_timeout_ms)
3208 XDLL_remove (daemon->normal_timeout_head, 3208 XDLL_remove (daemon->normal_timeout_head,
@@ -3286,7 +3286,7 @@ MHD_suspend_connection (struct MHD_Connection *connection)
3286 3286
3287#ifdef MHD_USE_THREADS 3287#ifdef MHD_USE_THREADS
3288 mhd_assert ( (! MHD_D_IS_USING_THREADS_ (daemon)) || \ 3288 mhd_assert ( (! MHD_D_IS_USING_THREADS_ (daemon)) || \
3289 (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) || \ 3289 MHD_D_IS_USING_THREAD_PER_CONN_ (daemon) || \
3290 MHD_thread_handle_ID_is_current_thread_ (daemon->tid) ); 3290 MHD_thread_handle_ID_is_current_thread_ (daemon->tid) );
3291#endif /* MHD_USE_THREADS */ 3291#endif /* MHD_USE_THREADS */
3292 3292
@@ -3496,7 +3496,7 @@ resume_suspended_connections (struct MHD_Daemon *daemon)
3496 * Insert connection into cleanup list. */ 3496 * Insert connection into cleanup list. */
3497 3497
3498 if ( (NULL != daemon->notify_completed) && 3498 if ( (NULL != daemon->notify_completed) &&
3499 (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 3499 (! MHD_D_IS_USING_THREAD_PER_CONN_ (daemon)) &&
3500 (pos->rq.client_aware) ) 3500 (pos->rq.client_aware) )
3501 { 3501 {
3502 daemon->notify_completed (daemon->notify_completed_cls, 3502 daemon->notify_completed (daemon->notify_completed_cls,
@@ -3988,9 +3988,9 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
3988 pos); 3988 pos);
3989#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 3989#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3990 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 3990 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
3991 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 3991 if (MHD_D_IS_USING_THREAD_PER_CONN_ (daemon) &&
3992 (! pos->thread_joined) && 3992 (! pos->thread_joined) &&
3993 (! MHD_thread_handle_ID_join_thread_ (pos->tid)) ) 3993 (! MHD_thread_handle_ID_join_thread_ (pos->tid)) )
3994 MHD_PANIC (_ ("Failed to join a thread.\n")); 3994 MHD_PANIC (_ ("Failed to join a thread.\n"));
3995#endif 3995#endif
3996#ifdef UPGRADE_SUPPORT 3996#ifdef UPGRADE_SUPPORT
@@ -4166,7 +4166,7 @@ MHD_get_timeout64 (struct MHD_Daemon *daemon,
4166 MHD_thread_handle_ID_is_current_thread_ (daemon->tid) ); 4166 MHD_thread_handle_ID_is_current_thread_ (daemon->tid) );
4167#endif /* MHD_USE_THREADS */ 4167#endif /* MHD_USE_THREADS */
4168 4168
4169 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 4169 if (MHD_D_IS_USING_THREAD_PER_CONN_ (daemon))
4170 { 4170 {
4171#ifdef HAVE_MESSAGES 4171#ifdef HAVE_MESSAGES
4172 MHD_DLOG (daemon, 4172 MHD_DLOG (daemon,
@@ -4741,10 +4741,10 @@ MHD_select (struct MHD_Daemon *daemon,
4741 err_state = MHD_NO; 4741 err_state = MHD_NO;
4742 if ( (0 != (daemon->options & MHD_TEST_ALLOW_SUSPEND_RESUME)) && 4742 if ( (0 != (daemon->options & MHD_TEST_ALLOW_SUSPEND_RESUME)) &&
4743 (MHD_NO != resume_suspended_connections (daemon)) && 4743 (MHD_NO != resume_suspended_connections (daemon)) &&
4744 (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) ) 4744 (! MHD_D_IS_USING_THREAD_PER_CONN_ (daemon)) )
4745 millisec = 0; 4745 millisec = 0;
4746 4746
4747 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 4747 if (! MHD_D_IS_USING_THREAD_PER_CONN_ (daemon))
4748 { 4748 {
4749 /* single-threaded, go over everything */ 4749 /* single-threaded, go over everything */
4750 if (MHD_NO == 4750 if (MHD_NO ==
@@ -4842,7 +4842,7 @@ MHD_select (struct MHD_Daemon *daemon,
4842 uint64_t mhd_tmo; 4842 uint64_t mhd_tmo;
4843 uint64_t select_tmo; 4843 uint64_t select_tmo;
4844 4844
4845 if ( (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 4845 if ( (! MHD_D_IS_USING_THREAD_PER_CONN_ (daemon)) &&
4846 (MHD_NO != MHD_get_timeout64 (daemon, &mhd_tmo)) ) 4846 (MHD_NO != MHD_get_timeout64 (daemon, &mhd_tmo)) )
4847 { 4847 {
4848 if ( (0 < millisec) && 4848 if ( (0 < millisec) &&
@@ -5234,7 +5234,7 @@ static enum MHD_Result
5234MHD_poll (struct MHD_Daemon *daemon, 5234MHD_poll (struct MHD_Daemon *daemon,
5235 int may_block) 5235 int may_block)
5236{ 5236{
5237 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 5237 if (! MHD_D_IS_USING_THREAD_PER_CONN_ (daemon))
5238 return MHD_poll_all (daemon, 5238 return MHD_poll_all (daemon,
5239 may_block ? -1 : 0); 5239 may_block ? -1 : 0);
5240 return MHD_poll_listen_socket (daemon, 5240 return MHD_poll_listen_socket (daemon,
@@ -5886,7 +5886,7 @@ close_connection (struct MHD_Connection *pos)
5886 mhd_assert (NULL == daemon->worker_pool); 5886 mhd_assert (NULL == daemon->worker_pool);
5887#endif /* MHD_USE_THREADS */ 5887#endif /* MHD_USE_THREADS */
5888 5888
5889 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 5889 if (MHD_D_IS_USING_THREAD_PER_CONN_ (daemon))
5890 { 5890 {
5891 MHD_connection_mark_closed_ (pos); 5891 MHD_connection_mark_closed_ (pos);
5892 return; /* must let thread to do the rest */ 5892 return; /* must let thread to do the rest */
@@ -6671,7 +6671,7 @@ parse_options_va (struct MHD_Daemon *daemon,
6671#endif 6671#endif
6672 return MHD_NO; 6672 return MHD_NO;
6673 } 6673 }
6674 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 6674 if (MHD_D_IS_USING_THREAD_PER_CONN_ (daemon))
6675 { 6675 {
6676#ifdef HAVE_MESSAGES 6676#ifdef HAVE_MESSAGES
6677 MHD_DLOG (daemon, 6677 MHD_DLOG (daemon,
@@ -7665,9 +7665,9 @@ MHD_start_daemon_va (unsigned int flags,
7665 } 7665 }
7666#endif 7666#endif
7667 7667
7668 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 7668 if (MHD_D_IS_USING_THREAD_PER_CONN_ (daemon)
7669 && ((NULL != daemon->notify_completed) 7669 && ((NULL != daemon->notify_completed)
7670 || (NULL != daemon->notify_connection)) ) 7670 || (NULL != daemon->notify_connection)) )
7671 *pflags |= MHD_USE_ITC; /* requires ITC */ 7671 *pflags |= MHD_USE_ITC; /* requires ITC */
7672 7672
7673#ifdef _DEBUG 7673#ifdef _DEBUG
@@ -8185,7 +8185,7 @@ MHD_start_daemon_va (unsigned int flags,
8185#endif 8185#endif
8186 ) 8186 )
8187 { 8187 {
8188 if (0 != (*pflags & MHD_USE_THREAD_PER_CONNECTION)) 8188 if (MHD_D_IS_USING_THREAD_PER_CONN_ (daemon))
8189 { 8189 {
8190#ifdef HAVE_MESSAGES 8190#ifdef HAVE_MESSAGES
8191 MHD_DLOG (daemon, 8191 MHD_DLOG (daemon,
@@ -8271,8 +8271,7 @@ MHD_start_daemon_va (unsigned int flags,
8271 goto free_and_fail; 8271 goto free_and_fail;
8272 } 8272 }
8273 if (! MHD_create_named_thread_ (&daemon->tid, 8273 if (! MHD_create_named_thread_ (&daemon->tid,
8274 (*pflags 8274 MHD_D_IS_USING_THREAD_PER_CONN_ (daemon) ?
8275 & MHD_USE_THREAD_PER_CONNECTION) ?
8276 "MHD-listen" : "MHD-single", 8275 "MHD-listen" : "MHD-single",
8277 daemon->thread_stack_size, 8276 daemon->thread_stack_size,
8278 &MHD_polling_thread, 8277 &MHD_polling_thread,
@@ -8569,8 +8568,7 @@ static void
8569close_all_connections (struct MHD_Daemon *daemon) 8568close_all_connections (struct MHD_Daemon *daemon)
8570{ 8569{
8571 struct MHD_Connection *pos; 8570 struct MHD_Connection *pos;
8572 const bool used_thr_p_c = (0 != (daemon->options 8571 const bool used_thr_p_c = MHD_D_IS_USING_THREAD_PER_CONN_ (daemon);
8573 & MHD_USE_THREAD_PER_CONNECTION));
8574#ifdef UPGRADE_SUPPORT 8572#ifdef UPGRADE_SUPPORT
8575 const bool upg_allowed = (0 != (daemon->options & MHD_ALLOW_UPGRADE)); 8573 const bool upg_allowed = (0 != (daemon->options & MHD_ALLOW_UPGRADE));
8576#endif /* UPGRADE_SUPPORT */ 8574#endif /* UPGRADE_SUPPORT */
@@ -8582,7 +8580,7 @@ close_all_connections (struct MHD_Daemon *daemon)
8582 8580
8583#ifdef MHD_USE_THREADS 8581#ifdef MHD_USE_THREADS
8584 mhd_assert ( (! MHD_D_IS_USING_THREADS_ (daemon)) || \ 8582 mhd_assert ( (! MHD_D_IS_USING_THREADS_ (daemon)) || \
8585 (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) || \ 8583 MHD_D_IS_USING_THREAD_PER_CONN_ (daemon) || \
8586 MHD_thread_handle_ID_is_current_thread_ (daemon->tid) ); 8584 MHD_thread_handle_ID_is_current_thread_ (daemon->tid) );
8587 mhd_assert (NULL == daemon->worker_pool); 8585 mhd_assert (NULL == daemon->worker_pool);
8588#endif /* MHD_USE_THREADS */ 8586#endif /* MHD_USE_THREADS */
@@ -8710,9 +8708,9 @@ close_all_connections (struct MHD_Daemon *daemon)
8710 shutdown (pos->socket_fd, 8708 shutdown (pos->socket_fd,
8711 SHUT_RDWR); 8709 SHUT_RDWR);
8712#ifdef MHD_WINSOCK_SOCKETS 8710#ifdef MHD_WINSOCK_SOCKETS
8713 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 8711 if (MHD_D_IS_USING_THREAD_PER_CONN_ (daemon) &&
8714 (MHD_ITC_IS_VALID_ (daemon->itc)) && 8712 (MHD_ITC_IS_VALID_ (daemon->itc)) &&
8715 (! MHD_itc_activate_ (daemon->itc, "e")) ) 8713 (! MHD_itc_activate_ (daemon->itc, "e")) )
8716 MHD_PANIC (_ ("Failed to signal shutdown via inter-thread " \ 8714 MHD_PANIC (_ ("Failed to signal shutdown via inter-thread " \
8717 "communication channel.\n")); 8715 "communication channel.\n"));
8718#endif 8716#endif
@@ -8760,8 +8758,8 @@ close_all_connections (struct MHD_Daemon *daemon)
8760 while (NULL != (pos = daemon->connections_tail)) 8758 while (NULL != (pos = daemon->connections_tail))
8761 { 8759 {
8762#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 8760#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8763 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 8761 if (MHD_D_IS_USING_THREAD_PER_CONN_ (daemon) &&
8764 (! pos->thread_joined) ) 8762 (! pos->thread_joined) )
8765 MHD_PANIC (_ ("Failed to join a thread.\n")); 8763 MHD_PANIC (_ ("Failed to join a thread.\n"));
8766#endif 8764#endif
8767 close_connection (pos); 8765 close_connection (pos);