diff options
Diffstat (limited to 'src/microhttpd/daemon.c')
-rw-r--r-- | src/microhttpd/daemon.c | 174 |
1 files changed, 152 insertions, 22 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c index 7a310c1f..926a983e 100644 --- a/src/microhttpd/daemon.c +++ b/src/microhttpd/daemon.c | |||
@@ -26,7 +26,9 @@ | |||
26 | * @author Karlson2k (Evgeny Grin) | 26 | * @author Karlson2k (Evgeny Grin) |
27 | */ | 27 | */ |
28 | #include "platform.h" | 28 | #include "platform.h" |
29 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
29 | #include "mhd_threads.h" | 30 | #include "mhd_threads.h" |
31 | #endif | ||
30 | #include "internal.h" | 32 | #include "internal.h" |
31 | #include "response.h" | 33 | #include "response.h" |
32 | #include "connection.h" | 34 | #include "connection.h" |
@@ -34,7 +36,9 @@ | |||
34 | #include "mhd_limits.h" | 36 | #include "mhd_limits.h" |
35 | #include "autoinit_funcs.h" | 37 | #include "autoinit_funcs.h" |
36 | #include "mhd_mono_clock.h" | 38 | #include "mhd_mono_clock.h" |
39 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
37 | #include "mhd_locks.h" | 40 | #include "mhd_locks.h" |
41 | #endif | ||
38 | #include "mhd_sockets.h" | 42 | #include "mhd_sockets.h" |
39 | #include "mhd_itc.h" | 43 | #include "mhd_itc.h" |
40 | #include "mhd_compat.h" | 44 | #include "mhd_compat.h" |
@@ -181,12 +185,17 @@ static int mhd_winsock_inited_ = 0; | |||
181 | * Track global initialisation | 185 | * Track global initialisation |
182 | */ | 186 | */ |
183 | volatile int global_init_count = 0; | 187 | volatile int global_init_count = 0; |
188 | |||
189 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
184 | #ifdef MHD_MUTEX_STATIC_DEFN_INIT_ | 190 | #ifdef MHD_MUTEX_STATIC_DEFN_INIT_ |
185 | /** | 191 | /** |
186 | * Global initialisation mutex | 192 | * Global initialisation mutex |
187 | */ | 193 | */ |
188 | MHD_MUTEX_STATIC_DEFN_INIT_(global_init_mutex_); | 194 | MHD_MUTEX_STATIC_DEFN_INIT_(global_init_mutex_); |
189 | #endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */ | 195 | #endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */ |
196 | #endif | ||
197 | |||
198 | |||
190 | /** | 199 | /** |
191 | * Check whether global initialisation was performed | 200 | * Check whether global initialisation was performed |
192 | * and call initialiser if necessary. | 201 | * and call initialiser if necessary. |
@@ -194,14 +203,18 @@ MHD_MUTEX_STATIC_DEFN_INIT_(global_init_mutex_); | |||
194 | void | 203 | void |
195 | MHD_check_global_init_ (void) | 204 | MHD_check_global_init_ (void) |
196 | { | 205 | { |
206 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
197 | #ifdef MHD_MUTEX_STATIC_DEFN_INIT_ | 207 | #ifdef MHD_MUTEX_STATIC_DEFN_INIT_ |
198 | MHD_mutex_lock_chk_(&global_init_mutex_); | 208 | MHD_mutex_lock_chk_(&global_init_mutex_); |
199 | #endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */ | 209 | #endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */ |
210 | #endif | ||
200 | if (0 == global_init_count++) | 211 | if (0 == global_init_count++) |
201 | MHD_init (); | 212 | MHD_init (); |
213 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
202 | #ifdef MHD_MUTEX_STATIC_DEFN_INIT_ | 214 | #ifdef MHD_MUTEX_STATIC_DEFN_INIT_ |
203 | MHD_mutex_unlock_chk_(&global_init_mutex_); | 215 | MHD_mutex_unlock_chk_(&global_init_mutex_); |
204 | #endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */ | 216 | #endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */ |
217 | #endif | ||
205 | } | 218 | } |
206 | #endif /* ! _AUTOINIT_FUNCS_ARE_SUPPORTED */ | 219 | #endif /* ! _AUTOINIT_FUNCS_ARE_SUPPORTED */ |
207 | 220 | ||
@@ -263,7 +276,11 @@ struct MHD_IPCount | |||
263 | static void | 276 | static void |
264 | MHD_ip_count_lock (struct MHD_Daemon *daemon) | 277 | MHD_ip_count_lock (struct MHD_Daemon *daemon) |
265 | { | 278 | { |
279 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
266 | MHD_mutex_lock_chk_(&daemon->per_ip_connection_mutex); | 280 | MHD_mutex_lock_chk_(&daemon->per_ip_connection_mutex); |
281 | #else | ||
282 | (void) daemon; | ||
283 | #endif | ||
267 | } | 284 | } |
268 | 285 | ||
269 | 286 | ||
@@ -275,7 +292,11 @@ MHD_ip_count_lock (struct MHD_Daemon *daemon) | |||
275 | static void | 292 | static void |
276 | MHD_ip_count_unlock (struct MHD_Daemon *daemon) | 293 | MHD_ip_count_unlock (struct MHD_Daemon *daemon) |
277 | { | 294 | { |
295 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
278 | MHD_mutex_unlock_chk_(&daemon->per_ip_connection_mutex); | 296 | MHD_mutex_unlock_chk_(&daemon->per_ip_connection_mutex); |
297 | #else | ||
298 | (void) daemon; | ||
299 | #endif | ||
279 | } | 300 | } |
280 | 301 | ||
281 | 302 | ||
@@ -1177,7 +1198,7 @@ call_handlers (struct MHD_Connection *con, | |||
1177 | /* Note: no need to check for read buffer availability for | 1198 | /* Note: no need to check for read buffer availability for |
1178 | * TLS read-ready connection in 'read info' state as connection | 1199 | * TLS read-ready connection in 'read info' state as connection |
1179 | * without space in read buffer will be market as 'info block'. */ | 1200 | * without space in read buffer will be market as 'info block'. */ |
1180 | if ( (!con->daemon->data_already_pending) && | 1201 | if ( (! con->daemon->data_already_pending) && |
1181 | (0 == (con->daemon->options & MHD_USE_THREAD_PER_CONNECTION)) ) | 1202 | (0 == (con->daemon->options & MHD_USE_THREAD_PER_CONNECTION)) ) |
1182 | { | 1203 | { |
1183 | if (MHD_EVENT_LOOP_INFO_BLOCK == con->event_loop_info) | 1204 | if (MHD_EVENT_LOOP_INFO_BLOCK == con->event_loop_info) |
@@ -1230,7 +1251,7 @@ cleanup_upgraded_connection (struct MHD_Connection *connection) | |||
1230 | /** | 1251 | /** |
1231 | * Performs bi-directional forwarding on upgraded HTTPS connections | 1252 | * Performs bi-directional forwarding on upgraded HTTPS connections |
1232 | * based on the readyness state stored in the @a urh handle. | 1253 | * based on the readyness state stored in the @a urh handle. |
1233 | * @remark To be called only from thread that process | 1254 | * @remark To be called only from thread that processes |
1234 | * connection's recv(), send() and response. | 1255 | * connection's recv(), send() and response. |
1235 | * | 1256 | * |
1236 | * @param urh handle to process | 1257 | * @param urh handle to process |
@@ -1573,7 +1594,7 @@ process_urh (struct MHD_UpgradeResponseHandle *urh) | |||
1573 | } | 1594 | } |
1574 | #endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ | 1595 | #endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ |
1575 | 1596 | ||
1576 | 1597 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | |
1577 | #ifdef UPGRADE_SUPPORT | 1598 | #ifdef UPGRADE_SUPPORT |
1578 | /** | 1599 | /** |
1579 | * Main function of the thread that handles an individual connection | 1600 | * Main function of the thread that handles an individual connection |
@@ -2108,6 +2129,7 @@ exit: | |||
2108 | } | 2129 | } |
2109 | return (MHD_THRD_RTRN_TYPE_) 0; | 2130 | return (MHD_THRD_RTRN_TYPE_) 0; |
2110 | } | 2131 | } |
2132 | #endif | ||
2111 | 2133 | ||
2112 | 2134 | ||
2113 | /** | 2135 | /** |
@@ -2253,10 +2275,13 @@ internal_add_connection (struct MHD_Daemon *daemon, | |||
2253 | bool non_blck) | 2275 | bool non_blck) |
2254 | { | 2276 | { |
2255 | struct MHD_Connection *connection; | 2277 | struct MHD_Connection *connection; |
2278 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
2256 | unsigned int i; | 2279 | unsigned int i; |
2280 | #endif | ||
2257 | int eno = 0; | 2281 | int eno = 0; |
2258 | 2282 | ||
2259 | /* Direct add to master daemon could happen only with "external" add mode. */ | 2283 | /* Direct add to master daemon could happen only with "external" add mode. */ |
2284 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
2260 | mhd_assert ((NULL == daemon->worker_pool) || (external_add)); | 2285 | mhd_assert ((NULL == daemon->worker_pool) || (external_add)); |
2261 | if ((external_add) && (NULL != daemon->worker_pool)) | 2286 | if ((external_add) && (NULL != daemon->worker_pool)) |
2262 | { | 2287 | { |
@@ -2282,6 +2307,7 @@ internal_add_connection (struct MHD_Daemon *daemon, | |||
2282 | #endif | 2307 | #endif |
2283 | return MHD_NO; | 2308 | return MHD_NO; |
2284 | } | 2309 | } |
2310 | #endif | ||
2285 | 2311 | ||
2286 | if ( (! MHD_SCKT_FD_FITS_FDSET_(client_socket, | 2312 | if ( (! MHD_SCKT_FD_FITS_FDSET_(client_socket, |
2287 | NULL)) && | 2313 | NULL)) && |
@@ -2502,11 +2528,15 @@ internal_add_connection (struct MHD_Daemon *daemon, | |||
2502 | #endif /* ! HTTPS_SUPPORT */ | 2528 | #endif /* ! HTTPS_SUPPORT */ |
2503 | } | 2529 | } |
2504 | 2530 | ||
2531 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
2505 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); | 2532 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); |
2533 | #endif | ||
2506 | /* Firm check under lock. */ | 2534 | /* Firm check under lock. */ |
2507 | if (daemon->connections >= daemon->connection_limit) | 2535 | if (daemon->connections >= daemon->connection_limit) |
2508 | { | 2536 | { |
2537 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
2509 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); | 2538 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); |
2539 | #endif | ||
2510 | /* above connection limit - reject */ | 2540 | /* above connection limit - reject */ |
2511 | #ifdef HAVE_MESSAGES | 2541 | #ifdef HAVE_MESSAGES |
2512 | MHD_DLOG (daemon, | 2542 | MHD_DLOG (daemon, |
@@ -2527,14 +2557,15 @@ internal_add_connection (struct MHD_Daemon *daemon, | |||
2527 | DLL_insert (daemon->connections_head, | 2557 | DLL_insert (daemon->connections_head, |
2528 | daemon->connections_tail, | 2558 | daemon->connections_tail, |
2529 | connection); | 2559 | connection); |
2560 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
2530 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); | 2561 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); |
2531 | 2562 | #endif | |
2532 | if (NULL != daemon->notify_connection) | 2563 | if (NULL != daemon->notify_connection) |
2533 | daemon->notify_connection (daemon->notify_connection_cls, | 2564 | daemon->notify_connection (daemon->notify_connection_cls, |
2534 | connection, | 2565 | connection, |
2535 | &connection->socket_context, | 2566 | &connection->socket_context, |
2536 | MHD_CONNECTION_NOTIFY_STARTED); | 2567 | MHD_CONNECTION_NOTIFY_STARTED); |
2537 | 2568 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | |
2538 | /* attempt to create handler thread */ | 2569 | /* attempt to create handler thread */ |
2539 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) | 2570 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) |
2540 | { | 2571 | { |
@@ -2555,6 +2586,7 @@ internal_add_connection (struct MHD_Daemon *daemon, | |||
2555 | } | 2586 | } |
2556 | else | 2587 | else |
2557 | connection->pid = daemon->pid; | 2588 | connection->pid = daemon->pid; |
2589 | #endif | ||
2558 | #ifdef EPOLL_SUPPORT | 2590 | #ifdef EPOLL_SUPPORT |
2559 | if (0 != (daemon->options & MHD_USE_EPOLL)) | 2591 | if (0 != (daemon->options & MHD_USE_EPOLL)) |
2560 | { | 2592 | { |
@@ -2615,7 +2647,9 @@ internal_add_connection (struct MHD_Daemon *daemon, | |||
2615 | MHD_ip_limit_del (daemon, | 2647 | MHD_ip_limit_del (daemon, |
2616 | addr, | 2648 | addr, |
2617 | addrlen); | 2649 | addrlen); |
2650 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
2618 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); | 2651 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); |
2652 | #endif | ||
2619 | if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) | 2653 | if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) |
2620 | { | 2654 | { |
2621 | XDLL_remove (daemon->normal_timeout_head, | 2655 | XDLL_remove (daemon->normal_timeout_head, |
@@ -2625,7 +2659,9 @@ internal_add_connection (struct MHD_Daemon *daemon, | |||
2625 | DLL_remove (daemon->connections_head, | 2659 | DLL_remove (daemon->connections_head, |
2626 | daemon->connections_tail, | 2660 | daemon->connections_tail, |
2627 | connection); | 2661 | connection); |
2662 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
2628 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); | 2663 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); |
2664 | #endif | ||
2629 | MHD_pool_destroy (connection->pool); | 2665 | MHD_pool_destroy (connection->pool); |
2630 | free (connection->addr); | 2666 | free (connection->addr); |
2631 | free (connection); | 2667 | free (connection); |
@@ -2651,12 +2687,16 @@ internal_suspend_connection_ (struct MHD_Connection *connection) | |||
2651 | { | 2687 | { |
2652 | struct MHD_Daemon *daemon = connection->daemon; | 2688 | struct MHD_Daemon *daemon = connection->daemon; |
2653 | 2689 | ||
2690 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
2654 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); | 2691 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); |
2692 | #endif | ||
2655 | if (connection->resuming) | 2693 | if (connection->resuming) |
2656 | { | 2694 | { |
2657 | /* suspending again while we didn't even complete resuming yet */ | 2695 | /* suspending again while we didn't even complete resuming yet */ |
2658 | connection->resuming = false; | 2696 | connection->resuming = false; |
2697 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
2659 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); | 2698 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); |
2699 | #endif | ||
2660 | return; | 2700 | return; |
2661 | } | 2701 | } |
2662 | if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) | 2702 | if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) |
@@ -2700,7 +2740,9 @@ internal_suspend_connection_ (struct MHD_Connection *connection) | |||
2700 | connection->epoll_state |= MHD_EPOLL_STATE_SUSPENDED; | 2740 | connection->epoll_state |= MHD_EPOLL_STATE_SUSPENDED; |
2701 | } | 2741 | } |
2702 | #endif | 2742 | #endif |
2743 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
2703 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); | 2744 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); |
2745 | #endif | ||
2704 | } | 2746 | } |
2705 | 2747 | ||
2706 | 2748 | ||
@@ -2771,10 +2813,14 @@ MHD_resume_connection (struct MHD_Connection *connection) | |||
2771 | 2813 | ||
2772 | if (0 == (daemon->options & MHD_TEST_ALLOW_SUSPEND_RESUME)) | 2814 | if (0 == (daemon->options & MHD_TEST_ALLOW_SUSPEND_RESUME)) |
2773 | MHD_PANIC (_("Cannot resume connections without enabling MHD_ALLOW_SUSPEND_RESUME!\n")); | 2815 | MHD_PANIC (_("Cannot resume connections without enabling MHD_ALLOW_SUSPEND_RESUME!\n")); |
2816 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
2774 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); | 2817 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); |
2818 | #endif | ||
2775 | connection->resuming = true; | 2819 | connection->resuming = true; |
2776 | daemon->resuming = true; | 2820 | daemon->resuming = true; |
2821 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
2777 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); | 2822 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); |
2823 | #endif | ||
2778 | if ( (MHD_ITC_IS_VALID_(daemon->itc)) && | 2824 | if ( (MHD_ITC_IS_VALID_(daemon->itc)) && |
2779 | (! MHD_itc_activate_ (daemon->itc, "r")) ) | 2825 | (! MHD_itc_activate_ (daemon->itc, "r")) ) |
2780 | { | 2826 | { |
@@ -2802,11 +2848,13 @@ resume_suspended_connections (struct MHD_Daemon *daemon) | |||
2802 | struct MHD_Connection *prev = NULL; | 2848 | struct MHD_Connection *prev = NULL; |
2803 | int ret; | 2849 | int ret; |
2804 | const bool used_thr_p_c = (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)); | 2850 | const bool used_thr_p_c = (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)); |
2851 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
2805 | mhd_assert (NULL == daemon->worker_pool); | 2852 | mhd_assert (NULL == daemon->worker_pool); |
2806 | 2853 | #endif | |
2807 | ret = MHD_NO; | 2854 | ret = MHD_NO; |
2855 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
2808 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); | 2856 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); |
2809 | 2857 | #endif | |
2810 | if (daemon->resuming) | 2858 | if (daemon->resuming) |
2811 | { | 2859 | { |
2812 | prev = daemon->suspended_connections_tail; | 2860 | prev = daemon->suspended_connections_tail; |
@@ -2899,7 +2947,9 @@ resume_suspended_connections (struct MHD_Daemon *daemon) | |||
2899 | #endif /* UPGRADE_SUPPORT */ | 2947 | #endif /* UPGRADE_SUPPORT */ |
2900 | pos->resuming = false; | 2948 | pos->resuming = false; |
2901 | } | 2949 | } |
2950 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
2902 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); | 2951 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); |
2952 | #endif | ||
2903 | if ( (used_thr_p_c) && | 2953 | if ( (used_thr_p_c) && |
2904 | (MHD_NO != ret) ) | 2954 | (MHD_NO != ret) ) |
2905 | { /* Wake up suspended connections. */ | 2955 | { /* Wake up suspended connections. */ |
@@ -3062,9 +3112,13 @@ MHD_accept_connection (struct MHD_Daemon *daemon) | |||
3062 | } | 3112 | } |
3063 | else | 3113 | else |
3064 | { | 3114 | { |
3115 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
3065 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); | 3116 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); |
3117 | #endif | ||
3066 | daemon->at_limit = true; | 3118 | daemon->at_limit = true; |
3119 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
3067 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); | 3120 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); |
3121 | #endif | ||
3068 | #ifdef HAVE_MESSAGES | 3122 | #ifdef HAVE_MESSAGES |
3069 | MHD_DLOG (daemon, | 3123 | MHD_DLOG (daemon, |
3070 | _("Hit process or system resource limit at %u connections, temporarily suspending accept(). Consider setting a lower MHD_OPTION_CONNECTION_LIMIT.\n"), | 3124 | _("Hit process or system resource limit at %u connections, temporarily suspending accept(). Consider setting a lower MHD_OPTION_CONNECTION_LIMIT.\n"), |
@@ -3126,18 +3180,21 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon) | |||
3126 | { | 3180 | { |
3127 | struct MHD_Connection *pos; | 3181 | struct MHD_Connection *pos; |
3128 | 3182 | ||
3183 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
3129 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); | 3184 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); |
3185 | #endif | ||
3130 | while (NULL != (pos = daemon->cleanup_tail)) | 3186 | while (NULL != (pos = daemon->cleanup_tail)) |
3131 | { | 3187 | { |
3132 | DLL_remove (daemon->cleanup_head, | 3188 | DLL_remove (daemon->cleanup_head, |
3133 | daemon->cleanup_tail, | 3189 | daemon->cleanup_tail, |
3134 | pos); | 3190 | pos); |
3191 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
3135 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); | 3192 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); |
3136 | |||
3137 | if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && | 3193 | if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && |
3138 | (! pos->thread_joined) && | 3194 | (! pos->thread_joined) && |
3139 | (! MHD_join_thread_ (pos->pid.handle)) ) | 3195 | (! MHD_join_thread_ (pos->pid.handle)) ) |
3140 | MHD_PANIC (_("Failed to join a thread\n")); | 3196 | MHD_PANIC (_("Failed to join a thread\n")); |
3197 | #endif | ||
3141 | #ifdef UPGRADE_SUPPORT | 3198 | #ifdef UPGRADE_SUPPORT |
3142 | cleanup_upgraded_connection (pos); | 3199 | cleanup_upgraded_connection (pos); |
3143 | #endif /* UPGRADE_SUPPORT */ | 3200 | #endif /* UPGRADE_SUPPORT */ |
@@ -3195,11 +3252,15 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon) | |||
3195 | free (pos->addr); | 3252 | free (pos->addr); |
3196 | free (pos); | 3253 | free (pos); |
3197 | 3254 | ||
3255 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
3198 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); | 3256 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); |
3257 | #endif | ||
3199 | daemon->connections--; | 3258 | daemon->connections--; |
3200 | daemon->at_limit = false; | 3259 | daemon->at_limit = false; |
3201 | } | 3260 | } |
3261 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
3202 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); | 3262 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); |
3263 | #endif | ||
3203 | } | 3264 | } |
3204 | 3265 | ||
3205 | 3266 | ||
@@ -4489,9 +4550,9 @@ close_connection (struct MHD_Connection *pos) | |||
4489 | } | 4550 | } |
4490 | MHD_connection_close_ (pos, | 4551 | MHD_connection_close_ (pos, |
4491 | MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN); | 4552 | MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN); |
4492 | 4553 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | |
4493 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); | 4554 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); |
4494 | 4555 | #endif | |
4495 | mhd_assert (! pos->suspended); | 4556 | mhd_assert (! pos->suspended); |
4496 | mhd_assert (! pos->resuming); | 4557 | mhd_assert (! pos->resuming); |
4497 | if (pos->connection_timeout == daemon->connection_timeout) | 4558 | if (pos->connection_timeout == daemon->connection_timeout) |
@@ -4508,11 +4569,13 @@ close_connection (struct MHD_Connection *pos) | |||
4508 | DLL_insert (daemon->cleanup_head, | 4569 | DLL_insert (daemon->cleanup_head, |
4509 | daemon->cleanup_tail, | 4570 | daemon->cleanup_tail, |
4510 | pos); | 4571 | pos); |
4511 | 4572 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | |
4512 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); | 4573 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); |
4574 | #endif | ||
4513 | } | 4575 | } |
4514 | 4576 | ||
4515 | 4577 | ||
4578 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
4516 | /** | 4579 | /** |
4517 | * Thread that runs the polling loop until the daemon | 4580 | * Thread that runs the polling loop until the daemon |
4518 | * is explicitly shut down. | 4581 | * is explicitly shut down. |
@@ -4548,6 +4611,7 @@ MHD_polling_thread (void *cls) | |||
4548 | 4611 | ||
4549 | return (MHD_THRD_RTRN_TYPE_)0; | 4612 | return (MHD_THRD_RTRN_TYPE_)0; |
4550 | } | 4613 | } |
4614 | #endif | ||
4551 | 4615 | ||
4552 | 4616 | ||
4553 | /** | 4617 | /** |
@@ -4567,6 +4631,7 @@ unescape_wrapper (void *cls, | |||
4567 | char *val) | 4631 | char *val) |
4568 | { | 4632 | { |
4569 | (void) cls; /* Mute compiler warning. */ | 4633 | (void) cls; /* Mute compiler warning. */ |
4634 | |||
4570 | (void) connection; /* Mute compiler warning. */ | 4635 | (void) connection; /* Mute compiler warning. */ |
4571 | return MHD_http_unescape (val); | 4636 | return MHD_http_unescape (val); |
4572 | } | 4637 | } |
@@ -4640,7 +4705,9 @@ MHD_start_daemon (unsigned int flags, | |||
4640 | MHD_socket | 4705 | MHD_socket |
4641 | MHD_quiesce_daemon (struct MHD_Daemon *daemon) | 4706 | MHD_quiesce_daemon (struct MHD_Daemon *daemon) |
4642 | { | 4707 | { |
4708 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
4643 | unsigned int i; | 4709 | unsigned int i; |
4710 | #endif | ||
4644 | MHD_socket ret; | 4711 | MHD_socket ret; |
4645 | 4712 | ||
4646 | ret = daemon->listen_fd; | 4713 | ret = daemon->listen_fd; |
@@ -4655,7 +4722,8 @@ MHD_quiesce_daemon (struct MHD_Daemon *daemon) | |||
4655 | #endif | 4722 | #endif |
4656 | return MHD_INVALID_SOCKET; | 4723 | return MHD_INVALID_SOCKET; |
4657 | } | 4724 | } |
4658 | 4725 | ||
4726 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
4659 | if (NULL != daemon->worker_pool) | 4727 | if (NULL != daemon->worker_pool) |
4660 | for (i = 0; i < daemon->worker_pool_size; i++) | 4728 | for (i = 0; i < daemon->worker_pool_size; i++) |
4661 | { | 4729 | { |
@@ -4680,6 +4748,7 @@ MHD_quiesce_daemon (struct MHD_Daemon *daemon) | |||
4680 | MHD_PANIC (_("Failed to signal quiesce via inter-thread communication channel")); | 4748 | MHD_PANIC (_("Failed to signal quiesce via inter-thread communication channel")); |
4681 | } | 4749 | } |
4682 | } | 4750 | } |
4751 | #endif | ||
4683 | daemon->was_quiesced = true; | 4752 | daemon->was_quiesced = true; |
4684 | #ifdef EPOLL_SUPPORT | 4753 | #ifdef EPOLL_SUPPORT |
4685 | if ( (0 != (daemon->options & MHD_USE_EPOLL)) && | 4754 | if ( (0 != (daemon->options & MHD_USE_EPOLL)) && |
@@ -4839,6 +4908,7 @@ parse_options_va (struct MHD_Daemon *daemon, | |||
4839 | daemon->uri_log_callback_cls = va_arg (ap, | 4908 | daemon->uri_log_callback_cls = va_arg (ap, |
4840 | void *); | 4909 | void *); |
4841 | break; | 4910 | break; |
4911 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
4842 | case MHD_OPTION_THREAD_POOL_SIZE: | 4912 | case MHD_OPTION_THREAD_POOL_SIZE: |
4843 | daemon->worker_pool_size = va_arg (ap, | 4913 | daemon->worker_pool_size = va_arg (ap, |
4844 | unsigned int); | 4914 | unsigned int); |
@@ -4893,6 +4963,7 @@ parse_options_va (struct MHD_Daemon *daemon, | |||
4893 | } | 4963 | } |
4894 | } | 4964 | } |
4895 | break; | 4965 | break; |
4966 | #endif | ||
4896 | #ifdef HTTPS_SUPPORT | 4967 | #ifdef HTTPS_SUPPORT |
4897 | case MHD_OPTION_HTTPS_MEM_KEY: | 4968 | case MHD_OPTION_HTTPS_MEM_KEY: |
4898 | pstr = va_arg (ap, | 4969 | pstr = va_arg (ap, |
@@ -5071,10 +5142,12 @@ parse_options_va (struct MHD_Daemon *daemon, | |||
5071 | void *); | 5142 | void *); |
5072 | #endif | 5143 | #endif |
5073 | break; | 5144 | break; |
5145 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
5074 | case MHD_OPTION_THREAD_STACK_SIZE: | 5146 | case MHD_OPTION_THREAD_STACK_SIZE: |
5075 | daemon->thread_stack_size = va_arg (ap, | 5147 | daemon->thread_stack_size = va_arg (ap, |
5076 | size_t); | 5148 | size_t); |
5077 | break; | 5149 | break; |
5150 | #endif | ||
5078 | #ifdef TCP_FASTOPEN | 5151 | #ifdef TCP_FASTOPEN |
5079 | case MHD_OPTION_TCP_FASTOPEN_QUEUE_SIZE: | 5152 | case MHD_OPTION_TCP_FASTOPEN_QUEUE_SIZE: |
5080 | daemon->fastopen_queue_size = va_arg (ap, | 5153 | daemon->fastopen_queue_size = va_arg (ap, |
@@ -5400,7 +5473,9 @@ MHD_start_daemon_va (unsigned int flags, | |||
5400 | #endif | 5473 | #endif |
5401 | const struct sockaddr *servaddr = NULL; | 5474 | const struct sockaddr *servaddr = NULL; |
5402 | socklen_t addrlen; | 5475 | socklen_t addrlen; |
5476 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
5403 | unsigned int i; | 5477 | unsigned int i; |
5478 | #endif | ||
5404 | enum MHD_FLAG eflags; /* same type as in MHD_Daemon */ | 5479 | enum MHD_FLAG eflags; /* same type as in MHD_Daemon */ |
5405 | enum MHD_FLAG *pflags; | 5480 | enum MHD_FLAG *pflags; |
5406 | 5481 | ||
@@ -5580,8 +5655,11 @@ MHD_start_daemon_va (unsigned int flags, | |||
5580 | #endif /* HAVE_MESSAGES */ | 5655 | #endif /* HAVE_MESSAGES */ |
5581 | #endif /* ! NDEBUG */ | 5656 | #endif /* ! NDEBUG */ |
5582 | 5657 | ||
5583 | if ( (0 != (*pflags & MHD_USE_ITC)) && | 5658 | if ( (0 != (*pflags & MHD_USE_ITC)) |
5584 | (0 == daemon->worker_pool_size) ) | 5659 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) |
5660 | && (0 == daemon->worker_pool_size) | ||
5661 | #endif | ||
5662 | ) | ||
5585 | { | 5663 | { |
5586 | if (! MHD_itc_init_ (daemon->itc)) | 5664 | if (! MHD_itc_init_ (daemon->itc)) |
5587 | { | 5665 | { |
@@ -5649,6 +5727,7 @@ MHD_start_daemon_va (unsigned int flags, | |||
5649 | } | 5727 | } |
5650 | } | 5728 | } |
5651 | 5729 | ||
5730 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
5652 | if (! MHD_mutex_init_ (&daemon->nnc_lock)) | 5731 | if (! MHD_mutex_init_ (&daemon->nnc_lock)) |
5653 | { | 5732 | { |
5654 | #ifdef HAVE_MESSAGES | 5733 | #ifdef HAVE_MESSAGES |
@@ -5664,10 +5743,16 @@ MHD_start_daemon_va (unsigned int flags, | |||
5664 | return NULL; | 5743 | return NULL; |
5665 | } | 5744 | } |
5666 | #endif | 5745 | #endif |
5746 | #endif | ||
5667 | 5747 | ||
5748 | <<<<<<< HEAD | ||
5668 | /* Thread pooling currently works only with internal select thread mode */ | 5749 | /* Thread pooling currently works only with internal select thread mode */ |
5750 | ======= | ||
5751 | /* Thread pooling currently works only with internal select thread model */ | ||
5752 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
5753 | >>>>>>> add build option to compile MHD without threads | ||
5669 | if ( (0 == (*pflags & MHD_USE_INTERNAL_POLLING_THREAD)) && | 5754 | if ( (0 == (*pflags & MHD_USE_INTERNAL_POLLING_THREAD)) && |
5670 | (daemon->worker_pool_size > 0) ) | 5755 | (daemon->worker_pool_size > 0) ) |
5671 | { | 5756 | { |
5672 | #ifdef HAVE_MESSAGES | 5757 | #ifdef HAVE_MESSAGES |
5673 | MHD_DLOG (daemon, | 5758 | MHD_DLOG (daemon, |
@@ -5675,7 +5760,7 @@ MHD_start_daemon_va (unsigned int flags, | |||
5675 | #endif | 5760 | #endif |
5676 | goto free_and_fail; | 5761 | goto free_and_fail; |
5677 | } | 5762 | } |
5678 | 5763 | #endif | |
5679 | if ( (MHD_INVALID_SOCKET == daemon->listen_fd) && | 5764 | if ( (MHD_INVALID_SOCKET == daemon->listen_fd) && |
5680 | (0 == (*pflags & MHD_USE_NO_LISTEN_SOCKET)) ) | 5765 | (0 == (*pflags & MHD_USE_NO_LISTEN_SOCKET)) ) |
5681 | { | 5766 | { |
@@ -6000,8 +6085,11 @@ MHD_start_daemon_va (unsigned int flags, | |||
6000 | _("Failed to set nonblocking mode on listening socket: %s\n"), | 6085 | _("Failed to set nonblocking mode on listening socket: %s\n"), |
6001 | MHD_socket_last_strerr_()); | 6086 | MHD_socket_last_strerr_()); |
6002 | #endif | 6087 | #endif |
6003 | if (0 != (*pflags & MHD_USE_EPOLL) || | 6088 | if (0 != (*pflags & MHD_USE_EPOLL) |
6004 | daemon->worker_pool_size > 0) | 6089 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) |
6090 | || (daemon->worker_pool_size > 0) | ||
6091 | #endif | ||
6092 | ) | ||
6005 | { | 6093 | { |
6006 | /* Accept must be non-blocking. Multiple children may wake up | 6094 | /* Accept must be non-blocking. Multiple children may wake up |
6007 | * to handle a new connection, but only one will win the race. | 6095 | * to handle a new connection, but only one will win the race. |
@@ -6026,8 +6114,11 @@ MHD_start_daemon_va (unsigned int flags, | |||
6026 | } | 6114 | } |
6027 | 6115 | ||
6028 | #ifdef EPOLL_SUPPORT | 6116 | #ifdef EPOLL_SUPPORT |
6029 | if ( (0 != (*pflags & MHD_USE_EPOLL)) && | 6117 | if ( (0 != (*pflags & MHD_USE_EPOLL)) |
6030 | (0 == daemon->worker_pool_size) ) | 6118 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) |
6119 | && (0 == daemon->worker_pool_size) | ||
6120 | #endif | ||
6121 | ) | ||
6031 | { | 6122 | { |
6032 | if (0 != (*pflags & MHD_USE_THREAD_PER_CONNECTION)) | 6123 | if (0 != (*pflags & MHD_USE_THREAD_PER_CONNECTION)) |
6033 | { | 6124 | { |
@@ -6042,6 +6133,7 @@ MHD_start_daemon_va (unsigned int flags, | |||
6042 | } | 6133 | } |
6043 | #endif /* EPOLL_SUPPORT */ | 6134 | #endif /* EPOLL_SUPPORT */ |
6044 | 6135 | ||
6136 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
6045 | if (! MHD_mutex_init_ (&daemon->per_ip_connection_mutex)) | 6137 | if (! MHD_mutex_init_ (&daemon->per_ip_connection_mutex)) |
6046 | { | 6138 | { |
6047 | #ifdef HAVE_MESSAGES | 6139 | #ifdef HAVE_MESSAGES |
@@ -6061,12 +6153,15 @@ MHD_start_daemon_va (unsigned int flags, | |||
6061 | MHD_DLOG (daemon, | 6153 | MHD_DLOG (daemon, |
6062 | _("MHD failed to initialize IP connection limit mutex\n")); | 6154 | _("MHD failed to initialize IP connection limit mutex\n")); |
6063 | #endif | 6155 | #endif |
6156 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
6064 | MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex); | 6157 | MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex); |
6158 | #endif | ||
6065 | if (MHD_INVALID_SOCKET != listen_fd) | 6159 | if (MHD_INVALID_SOCKET != listen_fd) |
6066 | MHD_socket_close_chk_ (listen_fd); | 6160 | MHD_socket_close_chk_ (listen_fd); |
6067 | goto free_and_fail; | 6161 | goto free_and_fail; |
6068 | } | 6162 | } |
6069 | } | 6163 | } |
6164 | #endif | ||
6070 | 6165 | ||
6071 | #ifdef HTTPS_SUPPORT | 6166 | #ifdef HTTPS_SUPPORT |
6072 | /* initialize HTTPS daemon certificate aspects & send / recv functions */ | 6167 | /* initialize HTTPS daemon certificate aspects & send / recv functions */ |
@@ -6079,12 +6174,15 @@ MHD_start_daemon_va (unsigned int flags, | |||
6079 | #endif | 6174 | #endif |
6080 | if (MHD_INVALID_SOCKET != listen_fd) | 6175 | if (MHD_INVALID_SOCKET != listen_fd) |
6081 | MHD_socket_close_chk_ (listen_fd); | 6176 | MHD_socket_close_chk_ (listen_fd); |
6177 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
6082 | if (0 == daemon->worker_pool_size) | 6178 | if (0 == daemon->worker_pool_size) |
6083 | MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex); | 6179 | MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex); |
6084 | MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex); | 6180 | MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex); |
6181 | #endif | ||
6085 | goto free_and_fail; | 6182 | goto free_and_fail; |
6086 | } | 6183 | } |
6087 | #endif /* HTTPS_SUPPORT */ | 6184 | #endif /* HTTPS_SUPPORT */ |
6185 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
6088 | if ( (0 != (*pflags & MHD_USE_INTERNAL_POLLING_THREAD)) && | 6186 | if ( (0 != (*pflags & MHD_USE_INTERNAL_POLLING_THREAD)) && |
6089 | (0 == (*pflags & MHD_USE_NO_LISTEN_SOCKET)) ) | 6187 | (0 == (*pflags & MHD_USE_NO_LISTEN_SOCKET)) ) |
6090 | { | 6188 | { |
@@ -6208,6 +6306,7 @@ MHD_start_daemon_va (unsigned int flags, | |||
6208 | } | 6306 | } |
6209 | } | 6307 | } |
6210 | } | 6308 | } |
6309 | #endif | ||
6211 | #ifdef HTTPS_SUPPORT | 6310 | #ifdef HTTPS_SUPPORT |
6212 | /* API promises to never use the password after initialization, | 6311 | /* API promises to never use the password after initialization, |
6213 | so we additionally NULL it here to not deref a dangling pointer. */ | 6312 | so we additionally NULL it here to not deref a dangling pointer. */ |
@@ -6216,6 +6315,7 @@ MHD_start_daemon_va (unsigned int flags, | |||
6216 | 6315 | ||
6217 | return daemon; | 6316 | return daemon; |
6218 | 6317 | ||
6318 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
6219 | thread_failed: | 6319 | thread_failed: |
6220 | /* If no worker threads created, then shut down normally. Calling | 6320 | /* If no worker threads created, then shut down normally. Calling |
6221 | MHD_stop_daemon (as we do below) doesn't work here since it | 6321 | MHD_stop_daemon (as we do below) doesn't work here since it |
@@ -6238,6 +6338,7 @@ thread_failed: | |||
6238 | daemon->worker_pool_size = i; | 6338 | daemon->worker_pool_size = i; |
6239 | MHD_stop_daemon (daemon); | 6339 | MHD_stop_daemon (daemon); |
6240 | return NULL; | 6340 | return NULL; |
6341 | #endif | ||
6241 | 6342 | ||
6242 | free_and_fail: | 6343 | free_and_fail: |
6243 | /* clean up basic memory state in 'daemon' and return NULL to | 6344 | /* clean up basic memory state in 'daemon' and return NULL to |
@@ -6263,8 +6364,10 @@ thread_failed: | |||
6263 | #endif /* EPOLL_SUPPORT */ | 6364 | #endif /* EPOLL_SUPPORT */ |
6264 | #ifdef DAUTH_SUPPORT | 6365 | #ifdef DAUTH_SUPPORT |
6265 | free (daemon->nnc); | 6366 | free (daemon->nnc); |
6367 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
6266 | MHD_mutex_destroy_chk_ (&daemon->nnc_lock); | 6368 | MHD_mutex_destroy_chk_ (&daemon->nnc_lock); |
6267 | #endif | 6369 | #endif |
6370 | #endif | ||
6268 | #ifdef HTTPS_SUPPORT | 6371 | #ifdef HTTPS_SUPPORT |
6269 | if (0 != (*pflags & MHD_USE_TLS)) | 6372 | if (0 != (*pflags & MHD_USE_TLS)) |
6270 | gnutls_priority_deinit (daemon->priority_cache); | 6373 | gnutls_priority_deinit (daemon->priority_cache); |
@@ -6297,7 +6400,9 @@ close_all_connections (struct MHD_Daemon *daemon) | |||
6297 | struct MHD_UpgradeResponseHandle *urhn; | 6400 | struct MHD_UpgradeResponseHandle *urhn; |
6298 | const bool used_tls = (0 != (daemon->options & MHD_USE_TLS)); | 6401 | const bool used_tls = (0 != (daemon->options & MHD_USE_TLS)); |
6299 | 6402 | ||
6403 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
6300 | mhd_assert (NULL == daemon->worker_pool); | 6404 | mhd_assert (NULL == daemon->worker_pool); |
6405 | #endif | ||
6301 | mhd_assert (daemon->shutdown); | 6406 | mhd_assert (daemon->shutdown); |
6302 | /* give upgraded HTTPS connections a chance to finish */ | 6407 | /* give upgraded HTTPS connections a chance to finish */ |
6303 | /* 'daemon->urh_head' is not used in thread-per-connection mode. */ | 6408 | /* 'daemon->urh_head' is not used in thread-per-connection mode. */ |
@@ -6325,7 +6430,9 @@ close_all_connections (struct MHD_Daemon *daemon) | |||
6325 | } | 6430 | } |
6326 | /* first, make sure all threads are aware of shutdown; need to | 6431 | /* first, make sure all threads are aware of shutdown; need to |
6327 | traverse DLLs in peace... */ | 6432 | traverse DLLs in peace... */ |
6433 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
6328 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); | 6434 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); |
6435 | #endif | ||
6329 | #ifdef UPGRADE_SUPPORT | 6436 | #ifdef UPGRADE_SUPPORT |
6330 | if (upg_allowed) | 6437 | if (upg_allowed) |
6331 | { | 6438 | { |
@@ -6379,6 +6486,7 @@ close_all_connections (struct MHD_Daemon *daemon) | |||
6379 | #endif | 6486 | #endif |
6380 | } | 6487 | } |
6381 | 6488 | ||
6489 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
6382 | /* now, collect per-connection threads */ | 6490 | /* now, collect per-connection threads */ |
6383 | if (used_thr_p_c) | 6491 | if (used_thr_p_c) |
6384 | { | 6492 | { |
@@ -6401,6 +6509,7 @@ close_all_connections (struct MHD_Daemon *daemon) | |||
6401 | } | 6509 | } |
6402 | } | 6510 | } |
6403 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); | 6511 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); |
6512 | #endif | ||
6404 | 6513 | ||
6405 | #ifdef UPGRADE_SUPPORT | 6514 | #ifdef UPGRADE_SUPPORT |
6406 | /* Finished threads with "upgraded" connections need to be moved | 6515 | /* Finished threads with "upgraded" connections need to be moved |
@@ -6417,9 +6526,11 @@ close_all_connections (struct MHD_Daemon *daemon) | |||
6417 | /* now that we're alone, move everyone to cleanup */ | 6526 | /* now that we're alone, move everyone to cleanup */ |
6418 | while (NULL != (pos = daemon->connections_tail)) | 6527 | while (NULL != (pos = daemon->connections_tail)) |
6419 | { | 6528 | { |
6529 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
6420 | if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && | 6530 | if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && |
6421 | (! pos->thread_joined) ) | 6531 | (! pos->thread_joined) ) |
6422 | MHD_PANIC (_("Failed to join a thread\n")); | 6532 | MHD_PANIC (_("Failed to join a thread\n")); |
6533 | #endif | ||
6423 | close_connection (pos); | 6534 | close_connection (pos); |
6424 | } | 6535 | } |
6425 | MHD_cleanup_connections (daemon); | 6536 | MHD_cleanup_connections (daemon); |
@@ -6436,8 +6547,10 @@ void | |||
6436 | MHD_stop_daemon (struct MHD_Daemon *daemon) | 6547 | MHD_stop_daemon (struct MHD_Daemon *daemon) |
6437 | { | 6548 | { |
6438 | MHD_socket fd; | 6549 | MHD_socket fd; |
6550 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
6439 | unsigned int i; | 6551 | unsigned int i; |
6440 | 6552 | #endif | |
6553 | |||
6441 | if (NULL == daemon) | 6554 | if (NULL == daemon) |
6442 | return; | 6555 | return; |
6443 | 6556 | ||
@@ -6447,6 +6560,7 @@ MHD_stop_daemon (struct MHD_Daemon *daemon) | |||
6447 | else | 6560 | else |
6448 | fd = daemon->listen_fd; | 6561 | fd = daemon->listen_fd; |
6449 | 6562 | ||
6563 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
6450 | if (NULL != daemon->worker_pool) | 6564 | if (NULL != daemon->worker_pool) |
6451 | { /* Master daemon with worker pool. */ | 6565 | { /* Master daemon with worker pool. */ |
6452 | mhd_assert (1 < daemon->worker_pool_size); | 6566 | mhd_assert (1 < daemon->worker_pool_size); |
@@ -6486,7 +6600,9 @@ MHD_stop_daemon (struct MHD_Daemon *daemon) | |||
6486 | #endif /* EPOLL_SUPPORT */ | 6600 | #endif /* EPOLL_SUPPORT */ |
6487 | } | 6601 | } |
6488 | else | 6602 | else |
6603 | #endif | ||
6489 | { /* Worker daemon or single daemon. */ | 6604 | { /* Worker daemon or single daemon. */ |
6605 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
6490 | if (0 != (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)) | 6606 | if (0 != (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)) |
6491 | { /* Worker daemon or single daemon with internal thread(s). */ | 6607 | { /* Worker daemon or single daemon with internal thread(s). */ |
6492 | mhd_assert (0 == daemon->worker_pool_size); | 6608 | mhd_assert (0 == daemon->worker_pool_size); |
@@ -6518,6 +6634,7 @@ MHD_stop_daemon (struct MHD_Daemon *daemon) | |||
6518 | /* close_all_connections() was called in daemon thread. */ | 6634 | /* close_all_connections() was called in daemon thread. */ |
6519 | } | 6635 | } |
6520 | else | 6636 | else |
6637 | #endif | ||
6521 | { | 6638 | { |
6522 | /* No internal threads are used for polling sockets. */ | 6639 | /* No internal threads are used for polling sockets. */ |
6523 | close_all_connections (daemon); | 6640 | close_all_connections (daemon); |
@@ -6536,7 +6653,9 @@ MHD_stop_daemon (struct MHD_Daemon *daemon) | |||
6536 | #endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ | 6653 | #endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ |
6537 | #endif /* EPOLL_SUPPORT */ | 6654 | #endif /* EPOLL_SUPPORT */ |
6538 | 6655 | ||
6656 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
6539 | MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex); | 6657 | MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex); |
6658 | #endif | ||
6540 | } | 6659 | } |
6541 | 6660 | ||
6542 | if (NULL == daemon->master) | 6661 | if (NULL == daemon->master) |
@@ -6565,10 +6684,13 @@ MHD_stop_daemon (struct MHD_Daemon *daemon) | |||
6565 | 6684 | ||
6566 | #ifdef DAUTH_SUPPORT | 6685 | #ifdef DAUTH_SUPPORT |
6567 | free (daemon->nnc); | 6686 | free (daemon->nnc); |
6687 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
6568 | MHD_mutex_destroy_chk_ (&daemon->nnc_lock); | 6688 | MHD_mutex_destroy_chk_ (&daemon->nnc_lock); |
6569 | #endif | 6689 | #endif |
6690 | #endif | ||
6691 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
6570 | MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex); | 6692 | MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex); |
6571 | 6693 | #endif | |
6572 | free (daemon); | 6694 | free (daemon); |
6573 | } | 6695 | } |
6574 | } | 6696 | } |
@@ -6611,6 +6733,7 @@ MHD_get_daemon_info (struct MHD_Daemon *daemon, | |||
6611 | * at the same time. */ | 6733 | * at the same time. */ |
6612 | MHD_cleanup_connections (daemon); | 6734 | MHD_cleanup_connections (daemon); |
6613 | } | 6735 | } |
6736 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
6614 | else if (daemon->worker_pool) | 6737 | else if (daemon->worker_pool) |
6615 | { | 6738 | { |
6616 | unsigned int i; | 6739 | unsigned int i; |
@@ -6622,6 +6745,7 @@ MHD_get_daemon_info (struct MHD_Daemon *daemon, | |||
6622 | daemon->connections += daemon->worker_pool[i].connections; | 6745 | daemon->connections += daemon->worker_pool[i].connections; |
6623 | } | 6746 | } |
6624 | } | 6747 | } |
6748 | #endif | ||
6625 | return (const union MHD_DaemonInfo *) &daemon->connections; | 6749 | return (const union MHD_DaemonInfo *) &daemon->connections; |
6626 | case MHD_DAEMON_INFO_FLAGS: | 6750 | case MHD_DAEMON_INFO_FLAGS: |
6627 | return (const union MHD_DaemonInfo *) &daemon->options; | 6751 | return (const union MHD_DaemonInfo *) &daemon->options; |
@@ -6833,6 +6957,12 @@ MHD_is_feature_supported(enum MHD_FEATURE feature) | |||
6833 | #else | 6957 | #else |
6834 | return MHD_NO; | 6958 | return MHD_NO; |
6835 | #endif | 6959 | #endif |
6960 | case MHD_FEATURE_THREADS: | ||
6961 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
6962 | return MHD_YES; | ||
6963 | #else | ||
6964 | return MHD_NO; | ||
6965 | #endif | ||
6836 | 6966 | ||
6837 | } | 6967 | } |
6838 | return MHD_NO; | 6968 | return MHD_NO; |