diff options
Diffstat (limited to 'src/microhttpd/daemon.c')
-rw-r--r-- | src/microhttpd/daemon.c | 80 |
1 files changed, 45 insertions, 35 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c index 1b89de10..b7980460 100644 --- a/src/microhttpd/daemon.c +++ b/src/microhttpd/daemon.c | |||
@@ -7294,19 +7294,6 @@ MHD_start_daemon_va (unsigned int flags, | |||
7294 | MHD_socket_close_chk_ (listen_fd); | 7294 | MHD_socket_close_chk_ (listen_fd); |
7295 | goto free_and_fail; | 7295 | goto free_and_fail; |
7296 | } | 7296 | } |
7297 | if (! MHD_mutex_init_ (&daemon->cleanup_connection_mutex)) | ||
7298 | { | ||
7299 | #ifdef HAVE_MESSAGES | ||
7300 | MHD_DLOG (daemon, | ||
7301 | _ ("MHD failed to initialize IP connection limit mutex.\n")); | ||
7302 | #endif | ||
7303 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
7304 | MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex); | ||
7305 | #endif | ||
7306 | if (MHD_INVALID_SOCKET != listen_fd) | ||
7307 | MHD_socket_close_chk_ (listen_fd); | ||
7308 | goto free_and_fail; | ||
7309 | } | ||
7310 | #endif | 7297 | #endif |
7311 | 7298 | ||
7312 | #ifdef HTTPS_SUPPORT | 7299 | #ifdef HTTPS_SUPPORT |
@@ -7321,7 +7308,6 @@ MHD_start_daemon_va (unsigned int flags, | |||
7321 | if (MHD_INVALID_SOCKET != listen_fd) | 7308 | if (MHD_INVALID_SOCKET != listen_fd) |
7322 | MHD_socket_close_chk_ (listen_fd); | 7309 | MHD_socket_close_chk_ (listen_fd); |
7323 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | 7310 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) |
7324 | MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex); | ||
7325 | MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex); | 7311 | MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex); |
7326 | #endif | 7312 | #endif |
7327 | goto free_and_fail; | 7313 | goto free_and_fail; |
@@ -7345,14 +7331,25 @@ MHD_start_daemon_va (unsigned int flags, | |||
7345 | #endif /* ! HAVE_LISTEN_SHUTDOWN */ | 7331 | #endif /* ! HAVE_LISTEN_SHUTDOWN */ |
7346 | if (0 == daemon->worker_pool_size) | 7332 | if (0 == daemon->worker_pool_size) |
7347 | { | 7333 | { |
7334 | if (! MHD_mutex_init_ (&daemon->cleanup_connection_mutex)) | ||
7335 | { | ||
7336 | #ifdef HAVE_MESSAGES | ||
7337 | MHD_DLOG (daemon, | ||
7338 | _ ("Failed to initialise internal lists mutex.\n")); | ||
7339 | #endif | ||
7340 | MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex); | ||
7341 | if (MHD_INVALID_SOCKET != listen_fd) | ||
7342 | MHD_socket_close_chk_ (listen_fd); | ||
7343 | goto free_and_fail; | ||
7344 | } | ||
7348 | if (! MHD_mutex_init_ (&daemon->new_connections_mutex)) | 7345 | if (! MHD_mutex_init_ (&daemon->new_connections_mutex)) |
7349 | { | 7346 | { |
7350 | #ifdef HAVE_MESSAGES | 7347 | #ifdef HAVE_MESSAGES |
7351 | MHD_DLOG (daemon, | 7348 | MHD_DLOG (daemon, |
7352 | _ ("Failed to initialise mutex.\n")); | 7349 | _ ("Failed to initialise mutex.\n")); |
7353 | #endif | 7350 | #endif |
7354 | MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex); | ||
7355 | MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex); | 7351 | MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex); |
7352 | MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex); | ||
7356 | if (MHD_INVALID_SOCKET != listen_fd) | 7353 | if (MHD_INVALID_SOCKET != listen_fd) |
7357 | MHD_socket_close_chk_ (listen_fd); | 7354 | MHD_socket_close_chk_ (listen_fd); |
7358 | goto free_and_fail; | 7355 | goto free_and_fail; |
@@ -7379,8 +7376,8 @@ MHD_start_daemon_va (unsigned int flags, | |||
7379 | MHD_strerror_ (errno)); | 7376 | MHD_strerror_ (errno)); |
7380 | #endif /* HAVE_MESSAGES */ | 7377 | #endif /* HAVE_MESSAGES */ |
7381 | MHD_mutex_destroy_chk_ (&daemon->new_connections_mutex); | 7378 | MHD_mutex_destroy_chk_ (&daemon->new_connections_mutex); |
7382 | MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex); | ||
7383 | MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex); | 7379 | MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex); |
7380 | MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex); | ||
7384 | if (MHD_INVALID_SOCKET != listen_fd) | 7381 | if (MHD_INVALID_SOCKET != listen_fd) |
7385 | MHD_socket_close_chk_ (listen_fd); | 7382 | MHD_socket_close_chk_ (listen_fd); |
7386 | goto free_and_fail; | 7383 | goto free_and_fail; |
@@ -7418,12 +7415,21 @@ MHD_start_daemon_va (unsigned int flags, | |||
7418 | d->master = daemon; | 7415 | d->master = daemon; |
7419 | d->worker_pool_size = 0; | 7416 | d->worker_pool_size = 0; |
7420 | d->worker_pool = NULL; | 7417 | d->worker_pool = NULL; |
7418 | if (! MHD_mutex_init_ (&d->cleanup_connection_mutex)) | ||
7419 | { | ||
7420 | #ifdef HAVE_MESSAGES | ||
7421 | MHD_DLOG (daemon, | ||
7422 | _ ("Failed to initialise internal lists mutex.\n")); | ||
7423 | #endif | ||
7424 | goto thread_failed; | ||
7425 | } | ||
7421 | if (! MHD_mutex_init_ (&d->new_connections_mutex)) | 7426 | if (! MHD_mutex_init_ (&d->new_connections_mutex)) |
7422 | { | 7427 | { |
7423 | #ifdef HAVE_MESSAGES | 7428 | #ifdef HAVE_MESSAGES |
7424 | MHD_DLOG (daemon, | 7429 | MHD_DLOG (daemon, |
7425 | _ ("Failed to initialise mutex.\n")); | 7430 | _ ("Failed to initialise mutex.\n")); |
7426 | #endif | 7431 | #endif |
7432 | MHD_mutex_destroy_chk_ (&d->cleanup_connection_mutex); | ||
7427 | goto thread_failed; | 7433 | goto thread_failed; |
7428 | } | 7434 | } |
7429 | if (0 != (*pflags & MHD_USE_ITC)) | 7435 | if (0 != (*pflags & MHD_USE_ITC)) |
@@ -7437,6 +7443,7 @@ MHD_start_daemon_va (unsigned int flags, | |||
7437 | MHD_itc_last_strerror_ () ); | 7443 | MHD_itc_last_strerror_ () ); |
7438 | #endif | 7444 | #endif |
7439 | MHD_mutex_destroy_chk_ (&d->new_connections_mutex); | 7445 | MHD_mutex_destroy_chk_ (&d->new_connections_mutex); |
7446 | MHD_mutex_destroy_chk_ (&d->cleanup_connection_mutex); | ||
7440 | goto thread_failed; | 7447 | goto thread_failed; |
7441 | } | 7448 | } |
7442 | if ( (0 == (*pflags & (MHD_USE_POLL | MHD_USE_EPOLL))) && | 7449 | if ( (0 == (*pflags & (MHD_USE_POLL | MHD_USE_EPOLL))) && |
@@ -7448,8 +7455,9 @@ MHD_start_daemon_va (unsigned int flags, | |||
7448 | _ ( | 7455 | _ ( |
7449 | "File descriptor for worker inter-thread communication channel exceeds maximum value.\n")); | 7456 | "File descriptor for worker inter-thread communication channel exceeds maximum value.\n")); |
7450 | #endif | 7457 | #endif |
7451 | MHD_mutex_destroy_chk_ (&d->new_connections_mutex); | ||
7452 | MHD_itc_destroy_chk_ (d->itc); | 7458 | MHD_itc_destroy_chk_ (d->itc); |
7459 | MHD_mutex_destroy_chk_ (&d->new_connections_mutex); | ||
7460 | MHD_mutex_destroy_chk_ (&d->cleanup_connection_mutex); | ||
7453 | goto thread_failed; | 7461 | goto thread_failed; |
7454 | } | 7462 | } |
7455 | } | 7463 | } |
@@ -7476,21 +7484,10 @@ MHD_start_daemon_va (unsigned int flags, | |||
7476 | if (MHD_ITC_IS_VALID_ (d->itc)) | 7484 | if (MHD_ITC_IS_VALID_ (d->itc)) |
7477 | MHD_itc_destroy_chk_ (d->itc); | 7485 | MHD_itc_destroy_chk_ (d->itc); |
7478 | MHD_mutex_destroy_chk_ (&d->new_connections_mutex); | 7486 | MHD_mutex_destroy_chk_ (&d->new_connections_mutex); |
7487 | MHD_mutex_destroy_chk_ (&d->cleanup_connection_mutex); | ||
7479 | goto thread_failed; | 7488 | goto thread_failed; |
7480 | } | 7489 | } |
7481 | #endif | 7490 | #endif |
7482 | /* Must init cleanup connection mutex for each worker */ | ||
7483 | if (! MHD_mutex_init_ (&d->cleanup_connection_mutex)) | ||
7484 | { | ||
7485 | #ifdef HAVE_MESSAGES | ||
7486 | MHD_DLOG (daemon, | ||
7487 | _ ("MHD failed to initialize cleanup connection mutex.\n")); | ||
7488 | #endif | ||
7489 | if (MHD_ITC_IS_VALID_ (d->itc)) | ||
7490 | MHD_itc_destroy_chk_ (d->itc); | ||
7491 | MHD_mutex_destroy_chk_ (&d->new_connections_mutex); | ||
7492 | goto thread_failed; | ||
7493 | } | ||
7494 | /* Some members must be used only in master daemon */ | 7491 | /* Some members must be used only in master daemon */ |
7495 | #if defined(MHD_USE_THREADS) | 7492 | #if defined(MHD_USE_THREADS) |
7496 | memset (&d->per_ip_connection_mutex, 1, | 7493 | memset (&d->per_ip_connection_mutex, 1, |
@@ -7530,6 +7527,7 @@ MHD_start_daemon_va (unsigned int flags, | |||
7530 | if (MHD_ITC_IS_VALID_ (d->itc)) | 7527 | if (MHD_ITC_IS_VALID_ (d->itc)) |
7531 | MHD_itc_destroy_chk_ (d->itc); | 7528 | MHD_itc_destroy_chk_ (d->itc); |
7532 | MHD_mutex_destroy_chk_ (&d->new_connections_mutex); | 7529 | MHD_mutex_destroy_chk_ (&d->new_connections_mutex); |
7530 | MHD_mutex_destroy_chk_ (&d->cleanup_connection_mutex); | ||
7533 | goto thread_failed; | 7531 | goto thread_failed; |
7534 | } | 7532 | } |
7535 | } | 7533 | } |
@@ -7537,12 +7535,27 @@ MHD_start_daemon_va (unsigned int flags, | |||
7537 | } | 7535 | } |
7538 | else | 7536 | else |
7539 | { /* Daemon without internal threads */ | 7537 | { /* Daemon without internal threads */ |
7538 | if (! MHD_mutex_init_ (&daemon->cleanup_connection_mutex)) | ||
7539 | { | ||
7540 | #ifdef HAVE_MESSAGES | ||
7541 | MHD_DLOG (daemon, | ||
7542 | _ ("Failed to initialise internal lists mutex.\n")); | ||
7543 | #endif | ||
7544 | MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex); | ||
7545 | if (MHD_INVALID_SOCKET != listen_fd) | ||
7546 | MHD_socket_close_chk_ (listen_fd); | ||
7547 | goto free_and_fail; | ||
7548 | } | ||
7540 | if (! MHD_mutex_init_ (&daemon->new_connections_mutex)) | 7549 | if (! MHD_mutex_init_ (&daemon->new_connections_mutex)) |
7541 | { | 7550 | { |
7542 | #ifdef HAVE_MESSAGES | 7551 | #ifdef HAVE_MESSAGES |
7543 | MHD_DLOG (daemon, | 7552 | MHD_DLOG (daemon, |
7544 | _ ("Failed to initialise mutex.\n")); | 7553 | _ ("Failed to initialise mutex.\n")); |
7545 | #endif | 7554 | #endif |
7555 | MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex); | ||
7556 | MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex); | ||
7557 | if (MHD_INVALID_SOCKET != listen_fd) | ||
7558 | MHD_socket_close_chk_ (listen_fd); | ||
7546 | goto free_and_fail; | 7559 | goto free_and_fail; |
7547 | } | 7560 | } |
7548 | } | 7561 | } |
@@ -7939,16 +7952,12 @@ MHD_stop_daemon (struct MHD_Daemon *daemon) | |||
7939 | MHD_PANIC (_ ("Failed to join a thread.\n")); | 7952 | MHD_PANIC (_ ("Failed to join a thread.\n")); |
7940 | } | 7953 | } |
7941 | /* close_all_connections() was called in daemon thread. */ | 7954 | /* close_all_connections() was called in daemon thread. */ |
7942 | MHD_mutex_destroy_chk_ (&daemon->new_connections_mutex); | ||
7943 | } | 7955 | } |
7944 | else | 7956 | else |
7945 | #endif | 7957 | #endif |
7946 | { | 7958 | { |
7947 | /* No internal threads are used for polling sockets. */ | 7959 | /* No internal threads are used for polling sockets. */ |
7948 | close_all_connections (daemon); | 7960 | close_all_connections (daemon); |
7949 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | ||
7950 | MHD_mutex_destroy_chk_ (&daemon->new_connections_mutex); | ||
7951 | #endif /* MHD_USE_POSIX_THREADS || MHD_USE_W32_THREADS */ | ||
7952 | } | 7961 | } |
7953 | mhd_assert (NULL == daemon->connections_head); | 7962 | mhd_assert (NULL == daemon->connections_head); |
7954 | mhd_assert (NULL == daemon->cleanup_head); | 7963 | mhd_assert (NULL == daemon->cleanup_head); |
@@ -7974,6 +7983,7 @@ MHD_stop_daemon (struct MHD_Daemon *daemon) | |||
7974 | 7983 | ||
7975 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | 7984 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) |
7976 | MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex); | 7985 | MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex); |
7986 | MHD_mutex_destroy_chk_ (&daemon->new_connections_mutex); | ||
7977 | #endif | 7987 | #endif |
7978 | } | 7988 | } |
7979 | 7989 | ||