aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/daemon.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-07-29 20:00:58 +0200
committerChristian Grothoff <christian@grothoff.org>2019-07-29 20:00:58 +0200
commit9c15b24f596dfd7374d8909a254ec2df76366300 (patch)
tree6046c16cb844db556ac8c545a257ead09fb441f5 /src/microhttpd/daemon.c
parent40bf201dc53465be1d2805039ef5963a21e44c08 (diff)
downloadlibmicrohttpd-9c15b24f596dfd7374d8909a254ec2df76366300.tar.gz
libmicrohttpd-9c15b24f596dfd7374d8909a254ec2df76366300.zip
ensure event loop keeps going in test, and indentation fixes
Diffstat (limited to 'src/microhttpd/daemon.c')
-rw-r--r--src/microhttpd/daemon.c114
1 files changed, 57 insertions, 57 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 3fc992de..7ce0fbb3 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -721,8 +721,8 @@ int
721MHD_get_fdset (struct MHD_Daemon *daemon, 721MHD_get_fdset (struct MHD_Daemon *daemon,
722 fd_set *read_fd_set, 722 fd_set *read_fd_set,
723 fd_set *write_fd_set, 723 fd_set *write_fd_set,
724 fd_set *except_fd_set, 724 fd_set *except_fd_set,
725 MHD_socket *max_fd) 725 MHD_socket *max_fd)
726{ 726{
727 return MHD_get_fdset2 (daemon, 727 return MHD_get_fdset2 (daemon,
728 read_fd_set, 728 read_fd_set,
@@ -2344,11 +2344,11 @@ psk_gnutls_adapter (gnutls_session_t session,
2344 */ 2344 */
2345static int 2345static int
2346internal_add_connection (struct MHD_Daemon *daemon, 2346internal_add_connection (struct MHD_Daemon *daemon,
2347 MHD_socket client_socket, 2347 MHD_socket client_socket,
2348 const struct sockaddr *addr, 2348 const struct sockaddr *addr,
2349 socklen_t addrlen, 2349 socklen_t addrlen,
2350 bool external_add, 2350 bool external_add,
2351 bool non_blck) 2351 bool non_blck)
2352{ 2352{
2353 struct MHD_Connection *connection; 2353 struct MHD_Connection *connection;
2354#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 2354#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
@@ -2362,8 +2362,8 @@ internal_add_connection (struct MHD_Daemon *daemon,
2362 if ((external_add) && (NULL != daemon->worker_pool)) 2362 if ((external_add) && (NULL != daemon->worker_pool))
2363 { 2363 {
2364 /* have a pool, try to find a pool with capacity; we use the 2364 /* have a pool, try to find a pool with capacity; we use the
2365 socket as the initial offset into the pool for load 2365 socket as the initial offset into the pool for load
2366 balancing */ 2366 balancing */
2367 for (i = 0; i < daemon->worker_pool_size; ++i) 2367 for (i = 0; i < daemon->worker_pool_size; ++i)
2368 { 2368 {
2369 struct MHD_Daemon * const worker = 2369 struct MHD_Daemon * const worker =
@@ -2448,7 +2448,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
2448 /* apply connection acceptance policy if present */ 2448 /* apply connection acceptance policy if present */
2449 if ( (NULL != daemon->apc) && 2449 if ( (NULL != daemon->apc) &&
2450 (MHD_NO == daemon->apc (daemon->apc_cls, 2450 (MHD_NO == daemon->apc (daemon->apc_cls,
2451 addr, 2451 addr,
2452 addrlen)) ) 2452 addrlen)) )
2453 { 2453 {
2454#if DEBUG_CLOSE 2454#if DEBUG_CLOSE
@@ -2472,8 +2472,8 @@ internal_add_connection (struct MHD_Daemon *daemon,
2472 eno = errno; 2472 eno = errno;
2473#ifdef HAVE_MESSAGES 2473#ifdef HAVE_MESSAGES
2474 MHD_DLOG (daemon, 2474 MHD_DLOG (daemon,
2475 "Error allocating memory: %s\n", 2475 "Error allocating memory: %s\n",
2476 MHD_strerror_ (errno)); 2476 MHD_strerror_ (errno));
2477#endif 2477#endif
2478 MHD_socket_close_chk_ (client_socket); 2478 MHD_socket_close_chk_ (client_socket);
2479 MHD_ip_limit_del (daemon, 2479 MHD_ip_limit_del (daemon,
@@ -2487,8 +2487,8 @@ internal_add_connection (struct MHD_Daemon *daemon,
2487 { 2487 {
2488#ifdef HAVE_MESSAGES 2488#ifdef HAVE_MESSAGES
2489 MHD_DLOG (daemon, 2489 MHD_DLOG (daemon,
2490 _("Error allocating memory: %s\n"), 2490 _("Error allocating memory: %s\n"),
2491 MHD_strerror_ (errno)); 2491 MHD_strerror_ (errno));
2492#endif 2492#endif
2493 MHD_socket_close_chk_ (client_socket); 2493 MHD_socket_close_chk_ (client_socket);
2494 MHD_ip_limit_del (daemon, 2494 MHD_ip_limit_del (daemon,
@@ -2507,8 +2507,8 @@ internal_add_connection (struct MHD_Daemon *daemon,
2507 eno = errno; 2507 eno = errno;
2508#ifdef HAVE_MESSAGES 2508#ifdef HAVE_MESSAGES
2509 MHD_DLOG (daemon, 2509 MHD_DLOG (daemon,
2510 _("Error allocating memory: %s\n"), 2510 _("Error allocating memory: %s\n"),
2511 MHD_strerror_ (errno)); 2511 MHD_strerror_ (errno));
2512#endif 2512#endif
2513 MHD_socket_close_chk_ (client_socket); 2513 MHD_socket_close_chk_ (client_socket);
2514 MHD_ip_limit_del (daemon, 2514 MHD_ip_limit_del (daemon,
@@ -2566,8 +2566,8 @@ internal_add_connection (struct MHD_Daemon *daemon,
2566 /* set needed credentials for certificate authentication. */ 2566 /* set needed credentials for certificate authentication. */
2567 case GNUTLS_CRD_CERTIFICATE: 2567 case GNUTLS_CRD_CERTIFICATE:
2568 gnutls_credentials_set (connection->tls_session, 2568 gnutls_credentials_set (connection->tls_session,
2569 GNUTLS_CRD_CERTIFICATE, 2569 GNUTLS_CRD_CERTIFICATE,
2570 daemon->x509_cred); 2570 daemon->x509_cred);
2571 break; 2571 break;
2572 case GNUTLS_CRD_PSK: 2572 case GNUTLS_CRD_PSK:
2573 gnutls_credentials_set (connection->tls_session, 2573 gnutls_credentials_set (connection->tls_session,
@@ -2596,18 +2596,18 @@ internal_add_connection (struct MHD_Daemon *daemon,
2596 } 2596 }
2597#if (GNUTLS_VERSION_NUMBER+0 >= 0x030109) && !defined(_WIN64) 2597#if (GNUTLS_VERSION_NUMBER+0 >= 0x030109) && !defined(_WIN64)
2598 gnutls_transport_set_int (connection->tls_session, 2598 gnutls_transport_set_int (connection->tls_session,
2599 (int)(client_socket)); 2599 (int)(client_socket));
2600#else /* GnuTLS before 3.1.9 or Win x64 */ 2600#else /* GnuTLS before 3.1.9 or Win x64 */
2601 gnutls_transport_set_ptr (connection->tls_session, 2601 gnutls_transport_set_ptr (connection->tls_session,
2602 (gnutls_transport_ptr_t)(intptr_t)(client_socket)); 2602 (gnutls_transport_ptr_t)(intptr_t)(client_socket));
2603#endif /* GnuTLS before 3.1.9 */ 2603#endif /* GnuTLS before 3.1.9 */
2604#ifdef MHD_TLSLIB_NEED_PUSH_FUNC 2604#ifdef MHD_TLSLIB_NEED_PUSH_FUNC
2605 gnutls_transport_set_push_function (connection->tls_session, 2605 gnutls_transport_set_push_function (connection->tls_session,
2606 MHD_tls_push_func_); 2606 MHD_tls_push_func_);
2607#endif /* MHD_TLSLIB_NEED_PUSH_FUNC */ 2607#endif /* MHD_TLSLIB_NEED_PUSH_FUNC */
2608 if (daemon->https_mem_trust) 2608 if (daemon->https_mem_trust)
2609 gnutls_certificate_server_set_request (connection->tls_session, 2609 gnutls_certificate_server_set_request (connection->tls_session,
2610 GNUTLS_CERT_REQUEST); 2610 GNUTLS_CERT_REQUEST);
2611#else /* ! HTTPS_SUPPORT */ 2611#else /* ! HTTPS_SUPPORT */
2612 eno = EINVAL; 2612 eno = EINVAL;
2613 goto cleanup; 2613 goto cleanup;
@@ -2641,8 +2641,8 @@ internal_add_connection (struct MHD_Daemon *daemon,
2641 connection); 2641 connection);
2642 } 2642 }
2643 DLL_insert (daemon->connections_head, 2643 DLL_insert (daemon->connections_head,
2644 daemon->connections_tail, 2644 daemon->connections_tail,
2645 connection); 2645 connection);
2646#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 2646#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
2647 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 2647 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
2648#endif 2648#endif
@@ -2661,13 +2661,13 @@ internal_add_connection (struct MHD_Daemon *daemon,
2661 &thread_main_handle_connection, 2661 &thread_main_handle_connection,
2662 connection)) 2662 connection))
2663 { 2663 {
2664 eno = errno; 2664 eno = errno;
2665#ifdef HAVE_MESSAGES 2665#ifdef HAVE_MESSAGES
2666 MHD_DLOG (daemon, 2666 MHD_DLOG (daemon,
2667 "Failed to create a thread: %s\n", 2667 "Failed to create a thread: %s\n",
2668 MHD_strerror_ (eno)); 2668 MHD_strerror_ (eno));
2669#endif 2669#endif
2670 goto cleanup; 2670 goto cleanup;
2671 } 2671 }
2672 } 2672 }
2673 else 2673 else
@@ -2683,9 +2683,9 @@ internal_add_connection (struct MHD_Daemon *daemon,
2683 event.events = EPOLLIN | EPOLLOUT | EPOLLPRI | EPOLLET; 2683 event.events = EPOLLIN | EPOLLOUT | EPOLLPRI | EPOLLET;
2684 event.data.ptr = connection; 2684 event.data.ptr = connection;
2685 if (0 != epoll_ctl (daemon->epoll_fd, 2685 if (0 != epoll_ctl (daemon->epoll_fd,
2686 EPOLL_CTL_ADD, 2686 EPOLL_CTL_ADD,
2687 client_socket, 2687 client_socket,
2688 &event)) 2688 &event))
2689 { 2689 {
2690 eno = errno; 2690 eno = errno;
2691#ifdef HAVE_MESSAGES 2691#ifdef HAVE_MESSAGES
@@ -2702,8 +2702,8 @@ internal_add_connection (struct MHD_Daemon *daemon,
2702 connection->epoll_state |= MHD_EPOLL_STATE_READ_READY | MHD_EPOLL_STATE_WRITE_READY 2702 connection->epoll_state |= MHD_EPOLL_STATE_READ_READY | MHD_EPOLL_STATE_WRITE_READY
2703 | MHD_EPOLL_STATE_IN_EREADY_EDLL; 2703 | MHD_EPOLL_STATE_IN_EREADY_EDLL;
2704 EDLL_insert (daemon->eready_head, 2704 EDLL_insert (daemon->eready_head,
2705 daemon->eready_tail, 2705 daemon->eready_tail,
2706 connection); 2706 connection);
2707 } 2707 }
2708 } 2708 }
2709 else /* This 'else' is combined with next 'if'. */ 2709 else /* This 'else' is combined with next 'if'. */
@@ -4263,7 +4263,7 @@ run_epoll_for_upgrade (struct MHD_Daemon *daemon)
4263 * will be moved immediately to cleanup list. Otherwise 4263 * will be moved immediately to cleanup list. Otherwise
4264 * connection will stay in suspended list until 'pos' will 4264 * connection will stay in suspended list until 'pos' will
4265 * be marked with 'was_closed' by application. */ 4265 * be marked with 'was_closed' by application. */
4266 MHD_resume_connection(pos->connection); 4266 MHD_resume_connection (pos->connection);
4267 } 4267 }
4268 } 4268 }
4269 4269
@@ -4346,8 +4346,8 @@ MHD_epoll (struct MHD_Daemon *daemon,
4346 } 4346 }
4347 4347
4348#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 4348#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
4349 if ( (! daemon->upgrade_fd_in_epoll) && 4349 if ( ( (! daemon->upgrade_fd_in_epoll) &&
4350 (-1 != daemon->epoll_upgrade_fd) ) 4350 (-1 != daemon->epoll_upgrade_fd) ) )
4351 { 4351 {
4352 event.events = EPOLLIN | EPOLLOUT; 4352 event.events = EPOLLIN | EPOLLOUT;
4353 event.data.ptr = (void *) upgrade_marker; 4353 event.data.ptr = (void *) upgrade_marker;
@@ -4388,7 +4388,7 @@ MHD_epoll (struct MHD_Daemon *daemon,
4388 if (MHD_YES == may_block) 4388 if (MHD_YES == may_block)
4389 { 4389 {
4390 if (MHD_YES == MHD_get_timeout (daemon, 4390 if (MHD_YES == MHD_get_timeout (daemon,
4391 &timeout_ll)) 4391 &timeout_ll))
4392 { 4392 {
4393 if (timeout_ll >= (MHD_UNSIGNED_LONG_LONG) INT_MAX) 4393 if (timeout_ll >= (MHD_UNSIGNED_LONG_LONG) INT_MAX)
4394 timeout_ms = INT_MAX; 4394 timeout_ms = INT_MAX;
@@ -4824,26 +4824,26 @@ MHD_quiesce_daemon (struct MHD_Daemon *daemon)
4824 if (NULL != daemon->worker_pool) 4824 if (NULL != daemon->worker_pool)
4825 for (i = 0; i < daemon->worker_pool_size; i++) 4825 for (i = 0; i < daemon->worker_pool_size; i++)
4826 { 4826 {
4827 daemon->worker_pool[i].was_quiesced = true; 4827 daemon->worker_pool[i].was_quiesced = true;
4828#ifdef EPOLL_SUPPORT 4828#ifdef EPOLL_SUPPORT
4829 if ( (0 != (daemon->options & MHD_USE_EPOLL)) && 4829 if ( (0 != (daemon->options & MHD_USE_EPOLL)) &&
4830 (-1 != daemon->worker_pool[i].epoll_fd) && 4830 (-1 != daemon->worker_pool[i].epoll_fd) &&
4831 (daemon->worker_pool[i].listen_socket_in_epoll) ) 4831 (daemon->worker_pool[i].listen_socket_in_epoll) )
4832 {
4833 if (0 != epoll_ctl (daemon->worker_pool[i].epoll_fd,
4834 EPOLL_CTL_DEL,
4835 ret,
4836 NULL))
4837 MHD_PANIC (_("Failed to remove listen FD from epoll set\n"));
4838 daemon->worker_pool[i].listen_socket_in_epoll = false;
4839 }
4840 else
4841#endif
4842 if (MHD_ITC_IS_VALID_(daemon->worker_pool[i].itc))
4843 { 4832 {
4844 if (! MHD_itc_activate_ (daemon->worker_pool[i].itc, "q")) 4833 if (0 != epoll_ctl (daemon->worker_pool[i].epoll_fd,
4845 MHD_PANIC (_("Failed to signal quiesce via inter-thread communication channel")); 4834 EPOLL_CTL_DEL,
4835 ret,
4836 NULL))
4837 MHD_PANIC (_("Failed to remove listen FD from epoll set\n"));
4838 daemon->worker_pool[i].listen_socket_in_epoll = false;
4846 } 4839 }
4840 else
4841#endif
4842 if (MHD_ITC_IS_VALID_(daemon->worker_pool[i].itc))
4843 {
4844 if (! MHD_itc_activate_ (daemon->worker_pool[i].itc, "q"))
4845 MHD_PANIC (_("Failed to signal quiesce via inter-thread communication channel"));
4846 }
4847 } 4847 }
4848#endif 4848#endif
4849 daemon->was_quiesced = true; 4849 daemon->was_quiesced = true;
@@ -4858,7 +4858,7 @@ MHD_quiesce_daemon (struct MHD_Daemon *daemon)
4858 NULL)) && 4858 NULL)) &&
4859 (ENOENT != errno) ) /* ENOENT can happen due to race with 4859 (ENOENT != errno) ) /* ENOENT can happen due to race with
4860 #MHD_epoll() */ 4860 #MHD_epoll() */
4861 MHD_PANIC ("Failed to remove listen FD from epoll set\n"); 4861 MHD_PANIC ("Failed to remove listen FD from epoll set\n");
4862 daemon->listen_socket_in_epoll = false; 4862 daemon->listen_socket_in_epoll = false;
4863 } 4863 }
4864#endif 4864#endif
@@ -4892,8 +4892,8 @@ typedef void
4892 */ 4892 */
4893static int 4893static int
4894parse_options_va (struct MHD_Daemon *daemon, 4894parse_options_va (struct MHD_Daemon *daemon,
4895 const struct sockaddr **servaddr, 4895 const struct sockaddr **servaddr,
4896 va_list ap); 4896 va_list ap);
4897 4897
4898 4898
4899/** 4899/**
@@ -4931,8 +4931,8 @@ parse_options (struct MHD_Daemon *daemon,
4931 */ 4931 */
4932static int 4932static int
4933parse_options_va (struct MHD_Daemon *daemon, 4933parse_options_va (struct MHD_Daemon *daemon,
4934 const struct sockaddr **servaddr, 4934 const struct sockaddr **servaddr,
4935 va_list ap) 4935 va_list ap)
4936{ 4936{
4937 enum MHD_OPTION opt; 4937 enum MHD_OPTION opt;
4938 struct MHD_OptionItem *oa; 4938 struct MHD_OptionItem *oa;