30#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
31#include "mhd_threads.h"
40#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
48#ifdef MHD_USE_SYS_TSEARCH
56#ifdef MHD_HTTPS_REQUIRE_GCRYPT
61#if defined(_WIN32) && ! defined(__CYGWIN__)
62#ifndef WIN32_LEAN_AND_MEAN
63#define WIN32_LEAN_AND_MEAN 1
68#ifdef MHD_USE_POSIX_THREADS
77#ifdef MHD_POSIX_SOCKETS
78#define MHD_MAX_CONNECTIONS_DEFAULT (FD_SETSIZE - 4)
80#define MHD_MAX_CONNECTIONS_DEFAULT (FD_SETSIZE - 2)
86#define MHD_POOL_SIZE_DEFAULT (32 * 1024)
137 _ (
"Fatal error in GNU libmicrohttpd %s:%u: %s\n"),
167#if defined(MHD_WINSOCK_SOCKETS)
174#ifdef _AUTOINIT_FUNCS_ARE_SUPPORTED
179#define MHD_check_global_init_() (void) 0
186#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
187#ifdef MHD_MUTEX_STATIC_DEFN_INIT_
203#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
204#ifdef MHD_MUTEX_STATIC_DEFN_INIT_
210#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
211#ifdef MHD_MUTEX_STATIC_DEFN_INIT_
311#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
327#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
366 struct MHD_IPCount *key)
380 sizeof(
addr4->sin_addr));
393 sizeof(
addr6->sin6_addr));
419 struct MHD_IPCount *key;
429 if (
NULL == (key = malloc (
sizeof(*key))))
450 _ (
"Failed to add IP connection count node.\n"));
460 key = (
struct MHD_IPCount *) node;
508 MHD_PANIC (
_ (
"Failed to find previously-added IP address.\n"));
514 MHD_PANIC (
_ (
"Previously-added IP address had counter of zero.\n"));
543#if GNUTLS_VERSION_MAJOR >= 3
544 if (
NULL != daemon->cert_callback)
547 daemon->cert_callback);
550#if GNUTLS_VERSION_NUMBER >= 0x030603
551 else if (
NULL != daemon->cert_callback2)
554 daemon->cert_callback2);
558 if (
NULL != daemon->https_mem_trust)
566 _ (
"Too long trust certificate.\n"));
570 cert.data = (
unsigned char *) daemon->https_mem_trust;
578 _ (
"Bad trust certificate format.\n"));
584 if (daemon->have_dhparams)
587 daemon->https_mem_dhparams);
590 if ( (
NULL != daemon->https_mem_cert) &&
591 (
NULL != daemon->https_mem_key) )
603 _ (
"Too long key or certificate.\n"));
607 key.data = (
unsigned char *) daemon->https_mem_key;
609 cert.data = (
unsigned char *) daemon->https_mem_cert;
612 if (
NULL != daemon->https_key_password)
614#if GNUTLS_VERSION_NUMBER >= 0x030111
619 daemon->https_key_password,
624 _ (
"Failed to setup x509 certificate/key: pre 3.X.X version " \
625 "of GnuTLS does not support setting key password.\n"));
638 _ (
"GnuTLS failed to setup x509 certificate/key: %s\n"),
643#if GNUTLS_VERSION_MAJOR >= 3
644 if (
NULL != daemon->cert_callback)
647#if GNUTLS_VERSION_NUMBER >= 0x030603
648 else if (
NULL != daemon->cert_callback2)
653 _ (
"You need to specify a certificate and key location.\n"));
668 switch (daemon->cred_type)
683 _ (
"Error: invalid credentials type %d specified.\n"),
743#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
772 if ( (
urh->in_buffer_used <
urh->in_buffer_size) &&
778 if ( (0 !=
urh->out_buffer_used) &&
787 ((0 !=
urh->in_buffer_size) ||
788 (0 !=
urh->out_buffer_size) ||
789 (0 !=
urh->out_buffer_used)))
797 if ( (
urh->out_buffer_used <
urh->out_buffer_size) &&
803 if ( (0 !=
urh->in_buffer_used) &&
812 ((0 !=
urh->out_buffer_size) ||
813 (0 !=
urh->in_buffer_size) ||
814 (0 !=
urh->in_buffer_used)))
887 if (
urh->in_buffer_used <
urh->in_buffer_size)
889 if (0 !=
urh->out_buffer_used)
895 ((0 !=
urh->in_buffer_size) ||
896 (0 !=
urh->out_buffer_size) ||
897 (0 !=
urh->out_buffer_used)))
900 if (
urh->out_buffer_used <
urh->out_buffer_size)
902 if (0 !=
urh->in_buffer_used)
908 ((0 !=
urh->out_buffer_size) ||
909 (0 !=
urh->in_buffer_size) ||
910 (0 !=
urh->in_buffer_used)))
925 p[0].fd =
urh->connection->socket_fd;
926 p[1].fd =
urh->mhd.socket;
1026#ifdef MHD_POSIX_SOCKETS
1039#ifdef MHD_POSIX_SOCKETS
1059#ifdef MHD_WINSOCK_SOCKETS
1072#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
1089#if _MHD_DEBUG_CONNECT
1093 _ (
"Maximum socket in select set: %d\n"),
1145 if ( (
NULL == daemon) ||
1156 _ (
"MHD_get_fdset2() called with except_fd_set "
1157 "set to NULL. Such behavior is unsupported.\n"));
1214 if (
con->tls_read_ready)
1288 if ( (!
con->daemon->data_already_pending) &&
1292 con->daemon->data_already_pending =
true;
1294 else if ( (
con->tls_read_ready) &&
1296 con->daemon->data_already_pending =
true;
1303#ifdef UPGRADE_SUPPORT
1331 connection->urh =
NULL;
1339#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
1362#ifdef MHD_USE_THREADS
1370 if (!
urh->was_closed)
1374 "Initiated daemon shutdown while \"upgraded\" connection was not closed.\n"));
1377 urh->was_closed =
true;
1384 if (0 <
urh->in_buffer_used)
1388 _ (
"Failed to forward to application "
1390 " bytes of data received from remote side: application shut down socket.\n"),
1400 if (0 !=
urh->out_buffer_size)
1403 urh->in_buffer_used = 0;
1407 urh->in_buffer_size = 0;
1429 (
urh->in_buffer_used <
urh->in_buffer_size) )
1440 &
urh->in_buffer[
urh->in_buffer_used],
1452 urh->in_buffer_size = 0;
1458 urh->in_buffer_used +=
res;
1470 urh->in_buffer_size = 0;
1478 (
urh->out_buffer_used <
urh->out_buffer_size) )
1488 &
urh->out_buffer[
urh->out_buffer_used],
1507 urh->out_buffer_size = 0;
1513 urh->out_buffer_used +=
res;
1524 urh->out_buffer_size = 0;
1532 (
urh->out_buffer_used > 0) )
1537 data_size =
urh->out_buffer_used;
1556 "Failed to forward to remote client "
1558 " bytes of data received from application: %s\n"),
1563 urh->out_buffer_used = 0;
1565 urh->out_buffer_size = 0;
1578 if (data_size > (
size_t)
res)
1583 if ( (0 ==
urh->out_buffer_used) &&
1591 urh->out_buffer_size = 0;
1600 (
urh->in_buffer_used > 0) )
1605 data_size =
urh->in_buffer_used;
1626 "Failed to forward to application "
1628 " bytes of data received from remote side: %s\n"),
1633 urh->in_buffer_used = 0;
1635 urh->in_buffer_size = 0;
1649 if (data_size > (
size_t)
res)
1654 if ( (0 ==
urh->in_buffer_used) &&
1660 urh->in_buffer_size = 0;
1669 (
urh->in_buffer_used <
urh->in_buffer_size) &&
1674 ( (0 !=
urh->out_buffer_size) ||
1675 (0 !=
urh->out_buffer_used) ) )
1679 if (0 <
urh->out_buffer_used)
1682 "Failed to forward to remote client "
1684 " bytes of data received from application: daemon shut down.\n"),
1688 urh->out_buffer_used = 0;
1692 urh->out_buffer_size = 0;
1700#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
1701#ifdef UPGRADE_SUPPORT
1725 while ( (0 !=
urh->in_buffer_size) ||
1726 (0 !=
urh->out_buffer_size) ||
1727 (0 !=
urh->in_buffer_used) ||
1728 (0 !=
urh->out_buffer_used) )
1752 _ (
"Error preparing select.\n"));
1761 if (((
con->tls_read_ready) &&
1762 (
urh->in_buffer_used <
urh->in_buffer_size)) ||
1787 _ (
"Error during select (%d): `%s'\n"),
1808 p[0].fd =
urh->connection->socket_fd;
1809 p[1].fd =
urh->mhd.socket;
1811 while ( (0 !=
urh->in_buffer_size) ||
1812 (0 !=
urh->out_buffer_size) ||
1813 (0 !=
urh->in_buffer_used) ||
1814 (0 !=
urh->out_buffer_used) )
1820 if (((
con->tls_read_ready) &&
1821 (
urh->in_buffer_used <
urh->in_buffer_size)) ||
1837 _ (
"Error during poll: `%s'\n"),
1932#define EXTRA_SLOTS 1
1934#define EXTRA_SLOTS 0
1951#ifdef UPGRADE_SUPPORT
1954 static const void *
const urh =
NULL;
1957 if ( (
con->suspended) &&
1970 #ifdef HAVE_MESSAGES
1972 _ (
"Failed to add FD to fd_set.\n"));
1988 _ (
"Error during select (%d): `%s'\n"),
2009 _ (
"Error during poll: `%s'\n"),
2032 || ( (
con->tls_read_ready) &&
2044 (
con->connection_timeout_ms > 0) )
2047#if (SIZEOF_UINT64_T - 2) >= SIZEOF_STRUCT_TIMEVAL_TV_SEC
2067 switch (
con->event_loop_info)
2108 _ (
"Failed to add FD to fd_set.\n"));
2126 _ (
"Error during select (%d): `%s'\n"),
2157 p[0].fd =
con->socket_fd;
2158 switch (
con->event_loop_info)
2195 _ (
"Error during poll: `%s'\n"),
2215#ifdef UPGRADE_SUPPORT
2221 (
con->client_aware) )
2224 &
con->client_context,
2226 con->client_aware =
false;
2232 con->urh->clean_ready =
true;
2247 _ (
"Processing thread terminating. Closing connection.\n"));
2265 shutdown (
con->socket_fd,
2277 "Failed to signal thread termination via inter-thread communication channel.\n"));
2297#if defined(HTTPS_SUPPORT)
2298#if defined(MHD_SEND_SPIPE_SUPPRESS_NEEDED) && \
2299 defined(MHD_SEND_SPIPE_SUPPRESS_POSSIBLE) && \
2300 ! defined(MHD_socket_nosignal_) && \
2301 (GNUTLS_VERSION_NUMBER + 0 < 0x030402) && defined(MSG_NOSIGNAL)
2307#define MHD_TLSLIB_NEED_PUSH_FUNC 1
2313#ifdef MHD_TLSLIB_NEED_PUSH_FUNC
2323#if (MHD_SCKT_SEND_MAX_SIZE_ < SSIZE_MAX) || (0 == SSIZE_MAX)
2349#if GNUTLS_VERSION_MAJOR >= 3
2355 if (
NULL == connection)
2359 MHD_PANIC (
_ (
"Internal server error. This should be impossible.\n"));
2363 daemon = connection->
daemon;
2364#if GNUTLS_VERSION_MAJOR >= 3
2365 if (
NULL == daemon->cred_callback)
2369 _ (
"PSK not supported by this server.\n"));
2373 if (0 != daemon->cred_callback (daemon->cred_callback_cls,
2384 "PSK authentication failed: gnutls_malloc failed to allocate memory.\n"));
2393 _ (
"PSK authentication failed: PSK too long.\n"));
2408 _ (
"PSK not supported by this server.\n"));
2454#if _MHD_DEBUG_CONNECT
2456 _ (
"Accepted connection on socket %d.\n"),
2469 "Server reached connection limit. Closing inbound connection.\n"));
2487 _ (
"Connection rejected by application. Closing connection.\n"));
2505 _ (
"Error allocating memory: %s\n"),
2532 _ (
"Error allocating memory: %s\n"),
2564#if (GNUTLS_VERSION_NUMBER + 0 >= 0x030500)
2572#if (GNUTLS_VERSION_NUMBER + 0 >= 0x030402)
2575#if GNUTLS_VERSION_MAJOR >= 3
2578#if (GNUTLS_VERSION_NUMBER + 0 >= 0x030603)
2582#if (GNUTLS_VERSION_NUMBER + 0 >= 0x030605)
2590 daemon->priority_cache)))
2592 if (
NULL != connection->tls_session)
2598 free (connection->
addr);
2602 _ (
"Failed to initialise TLS session.\n"));
2609#if (GNUTLS_VERSION_NUMBER + 0 >= 0x030200)
2610 if (!
daemon->disable_alpn)
2613 const char prt1[] =
"http/1.1";
2614 const char prt2[] =
"http/1.0";
2628 _ (
"Failed to set ALPN protocols.\n"));
2637 switch (
daemon->cred_type)
2656 "Failed to setup TLS credentials: unknown credential type %d.\n"),
2664 free (connection->
addr);
2666 MHD_PANIC (
_ (
"Unknown credential type.\n"));
2672#if (GNUTLS_VERSION_NUMBER + 0 >= 0x030109) && ! defined(_WIN64)
2679#ifdef MHD_TLSLIB_NEED_PUSH_FUNC
2683 if (
daemon->https_mem_trust)
2691 free (connection->
addr);
2693 MHD_PANIC (
_ (
"TLS connection on non-TLS daemon.\n"));
2706#ifdef MHD_USE_THREADS
2725 if (
NULL != connection->tls_session)
2735 free (connection->
addr);
2761#ifdef MHD_USE_THREADS
2777 _ (
"Error allocating memory: %s\n"),
2793 _ (
"Server reached connection limit. "
2794 "Closing inbound connection.\n"));
2819#ifdef MHD_USE_THREADS
2825 daemon->thread_stack_size,
2834 _ (
"Failed to create a new thread because it would "
2835 "have exceeded the system limit on the number of "
2836 "threads or no system resources available.\n"));
2840 _ (
"Failed to create a thread: %s\n"),
2852#ifdef MHD_USE_THREADS
2863 event.data.ptr = connection;
2872 _ (
"Call to epoll_ctl failed: %s\n"),
2889 daemon->eready_tail,
2923 if (
NULL != connection->tls_session)
2929 free (connection->
addr);
2982#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
2992 _ (
"New connection socket descriptor (%d) is not less " \
2993 "than FD_SETSIZE (%d).\n"),
3009 _ (
"Epoll mode supports only non-blocking sockets\n"));
3025 if (
NULL == connection)
3044 #ifdef HAVE_MESSAGES
3046 _ (
"Failed to signal new connection via inter-thread " \
3047 "communication channel.\n"));
3091 _ (
"Failed to start serving new connection.\n"));
3114#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3124#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3154 daemon->eready_tail,
3156 connection->epoll_state &=
3165 MHD_PANIC (
_ (
"Failed to remove FD from epoll set.\n"));
3166 connection->epoll_state &=
3172#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3215#ifdef MHD_USE_THREADS
3223 "Cannot suspend connections without enabling MHD_ALLOW_SUSPEND_RESUME!\n"));
3224#ifdef UPGRADE_SUPPORT
3225 if (
NULL != connection->urh)
3230 "Error: connection scheduled for \"upgrade\" cannot be suspended.\n"));
3254 "Cannot resume connections without enabling MHD_ALLOW_SUSPEND_RESUME!\n"));
3255#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3260#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3269 "Failed to signal resume via inter-thread communication channel.\n"));
3275#ifdef UPGRADE_SUPPORT
3288#if defined(MHD_USE_THREADS)
3295 connection->urh->was_closed =
true;
3304 _ (
"Failed to signal resume via " \
3305 "inter-thread communication channel.\n"));
3330#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3337#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3353#ifdef UPGRADE_SUPPORT
3356 static const void *
const urh =
NULL;
3362 ( (!
urh->was_closed) ||
3363 (!
urh->clean_ready) ) )
3397 MHD_PANIC (
"Resumed connection was already in EREADY set.\n");
3401 daemon->eready_tail,
3410#ifdef UPGRADE_SUPPORT
3435#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3447 "Failed to signal resume of connection via inter-thread communication channel.\n"));
3501 _ (
"MHD_add_connection() has been called for daemon started"
3502 " without MHD_USE_ITC flag.\nDaemon will not process newly"
3503 " added connection until any activity occurs in already"
3504 " added sockets.\n"));
3512 _ (
"Failed to set nonblocking mode on new client socket: %s\n"),
3520#ifndef MHD_WINSOCK_SOCKETS
3525#if defined(MHD_socket_nosignal_)
3531 "Failed to suppress SIGPIPE on new client socket: %s\n"),
3557 _ (
"Failed to set noninheritable mode on new client socket.\n"));
3561#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3632#ifdef MHD_USE_THREADS
3651#ifndef MHD_WINSOCK_SOCKETS
3661#ifdef MHD_ACCEPT_INHERIT_NONBLOCK
3666#ifndef MHD_WINSOCK_SOCKETS
3687 _ (
"Error accepting connection: %s\n"),
3704 _ (
"Hit process or system resource limit at FIRST " \
3705 "connection. This is really bad as there is no sane " \
3706 "way to proceed. Will try busy waiting for system " \
3707 "resources to become magically available.\n"));
3712#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3716#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3721 _ (
"Hit process or system resource limit at %u " \
3722 "connections, temporarily suspending accept(). " \
3723 "Consider setting a lower MHD_OPTION_CONNECTION_LIMIT.\n"),
3735 _ (
"Failed to set nonblocking mode on incoming connection " \
3749 _ (
"Failed to set noninheritable mode on incoming connection " \
3756#if defined(MHD_socket_nosignal_)
3761 _ (
"Failed to suppress SIGPIPE on incoming connection " \
3781#if _MHD_DEBUG_CONNECT
3783 _ (
"Accepted connection on socket %d\n"),
3812#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3823#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3828 MHD_PANIC (
_ (
"Failed to join a thread.\n"));
3830#ifdef UPGRADE_SUPPORT
3835 if (
NULL != pos->tls_session)
3859 if ( (-1 !=
daemon->epoll_fd) &&
3873 "Failed to remove FD from epoll set.\n"));
3891#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3897#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3943#ifdef MHD_USE_THREADS
3952 _ (
"Illegal call to MHD_get_timeout.\n"));
3980 if ( (
NULL != pos) &&
4004#if SIZEOF_UINT64_T > SIZEOF_UNSIGNED_LONG_LONG
4016#if defined(HAVE_POLL) || defined(EPOLL_SUPPORT)
4067#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
4098 while (
NULL != (pos = prev))
4114#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
4127 if ( (0 ==
urh->in_buffer_size) &&
4128 (0 ==
urh->out_buffer_size) &&
4129 (0 ==
urh->in_buffer_used) &&
4130 (0 ==
urh->out_buffer_used) )
4133 urh->clean_ready =
true;
4186 _ (
"MHD_run_from_select() called with except_fd_set "
4187 "set to NULL. Such behavior is deprecated.\n"));
4267 _ (
"Could not obtain daemon fdsets.\n"));
4284 _ (
"Could not add listen socket to fdset.\n"));
4298#if defined(MHD_WINSOCK_SOCKETS)
4319 _ (
"Could not add control inter-thread communication " \
4320 "channel FD to fdset.\n"));
4395 _ (
"select failed: %s\n"),
4424 unsigned int num_connections;
4427#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
4437 num_connections = 0;
4440#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
4442 num_connections += 2;
4459 _ (
"Error allocating memory: %s\n"),
4511#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
4535 _ (
"poll failed: %s\n"),
4570 while (
NULL != (pos = prev))
4574 if (
i >= num_connections)
4585#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
4588 if (
i >= num_connections)
4603 if ( (0 ==
urh->in_buffer_size) &&
4604 (0 ==
urh->out_buffer_size) &&
4605 (0 ==
urh->in_buffer_used) &&
4606 (0 ==
urh->out_buffer_used) )
4611 urh->clean_ready =
true;
4689 _ (
"poll failed: %s\n"),
4753#define MAX_EVENTS 128
4756#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
4770 if ( (0 ==
urh->in_buffer_size) &&
4771 (0 ==
urh->out_buffer_size) &&
4772 (0 ==
urh->in_buffer_used) &&
4773 (0 ==
urh->out_buffer_used) )
4779 (
urh->in_buffer_used <
urh->in_buffer_size) )
4782 (
urh->out_buffer_used <
urh->out_buffer_size) )
4785 (
urh->out_buffer_used > 0) )
4788 (
urh->in_buffer_used > 0) )
4810#ifdef MHD_USE_THREADS
4832 _ (
"Call to epoll_wait failed: %s\n"),
4843 if (
urh->clean_ready)
4868 if (!
urh->in_eready_list)
4874 daemon->eready_urh_tail,
4876 urh->in_eready_list =
true;
4881 prev = daemon->eready_urh_tail;
4882 while (
NULL != (pos = prev))
4889 daemon->eready_urh_tail,
4891 pos->in_eready_list =
false;
4894 if ( (0 == pos->in_buffer_size) &&
4895 (0 == pos->out_buffer_size) &&
4896 (0 == pos->in_buffer_used) &&
4897 (0 == pos->out_buffer_used) )
4900 pos->clean_ready =
true;
4935#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
4946#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
4951 if (-1 == daemon->epoll_fd)
4958 (! daemon->listen_socket_in_epoll) &&
4962 event.data.ptr = daemon;
4970 _ (
"Call to epoll_ctl failed: %s\n"),
4975 daemon->listen_socket_in_epoll =
true;
4978 (daemon->listen_socket_in_epoll) )
4986 MHD_PANIC (
"Failed to remove listen FD from epoll set.\n");
4987 daemon->listen_socket_in_epoll =
false;
4990#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
4991 if ( ( (! daemon->upgrade_fd_in_epoll) &&
4992 (-1 != daemon->epoll_upgrade_fd) ) )
4998 daemon->epoll_upgrade_fd,
5003 _ (
"Call to epoll_ctl failed: %s\n"),
5008 daemon->upgrade_fd_in_epoll =
true;
5011 if ( (daemon->listen_socket_in_epoll) &&
5022 MHD_PANIC (
_ (
"Failed to remove listen FD from epoll set.\n"));
5023 daemon->listen_socket_in_epoll =
false;
5057 _ (
"Call to epoll_wait failed: %s\n"),
5068#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5103 daemon->eready_tail,
5118 daemon->eready_tail,
5130 daemon->eready_tail,
5167 while (
NULL != (pos = prev))
5177 while (
NULL != (pos = prev))
5185#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
5191 prev = daemon->eready_tail;
5192 while (
NULL != (pos = prev))
5210 daemon->eready_tail,
5353#ifdef MHD_USE_THREADS
5365#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
5385#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
5391#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
5403#ifdef HAVE_PTHREAD_SIGMASK
5409#ifdef HAVE_PTHREAD_SIGMASK
5422 _ (
"Failed to block SIGPIPE on daemon thread: %s\n"),
5544#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
5558 "Using MHD_quiesce_daemon in this mode requires MHD_USE_ITC.\n"));
5563#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
5577 MHD_PANIC (
_ (
"Failed to remove listen FD from epoll set.\n"));
5586 "Failed to signal quiesce via inter-thread communication channel.\n"));
5593 (-1 != daemon->epoll_fd) &&
5594 (daemon->listen_socket_in_epoll) )
5602 MHD_PANIC (
"Failed to remove listen FD from epoll set.\n");
5603 daemon->listen_socket_in_epoll =
false;
5609 "failed to signal quiesce via inter-thread communication channel.\n"));
5685#if GNUTLS_VERSION_MAJOR >= 3
5688#if GNUTLS_VERSION_NUMBER >= 0x030603
5715#if (SIZEOF_UINT64_T - 2) <= SIZEOF_UNSIGNED_INT
5720 _ (
"The specified connection timeout (%u) is too large. " \
5721 "Maximum allowed value (%" PRIu64 ") will be used " \
5762#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
5771 "Warning: Zero size, specified for thread pool size, is ignored. "
5772 "Thread pool is not used.\n"));
5780 "Warning: \"1\", specified for thread pool size, is ignored. "
5781 "Thread pool is not used.\n"));
5785#if SIZEOF_UNSIGNED_INT >= (SIZEOF_SIZE_T - 2)
5794 _ (
"Specified thread pool size (%u) too big.\n"),
5806 _ (
"MHD_OPTION_THREAD_POOL_SIZE option is specified but "
5807 "MHD_USE_INTERNAL_POLLING_THREAD flag is not specified.\n"));
5815 _ (
"Both MHD_OPTION_THREAD_POOL_SIZE option and "
5816 "MHD_USE_THREAD_PER_CONNECTION flag are specified.\n"));
5828 daemon->https_mem_key =
pstr;
5833 "MHD HTTPS option %d passed to MHD but MHD_USE_TLS not set.\n"),
5841 daemon->https_key_password =
pstr;
5846 "MHD HTTPS option %d passed to MHD but MHD_USE_TLS not set.\n"),
5854 daemon->https_mem_cert =
pstr;
5859 "MHD HTTPS option %d passed to MHD but MHD_USE_TLS not set.\n"),
5867 daemon->https_mem_trust =
pstr;
5872 "MHD HTTPS option %d passed to MHD but MHD_USE_TLS not set.\n"),
5892 _ (
"Error initializing DH parameters.\n"));
5902 _ (
"Diffie-Hellman parameters string too long.\n"));
5913 _ (
"Bad Diffie-Hellman parameters format.\n"));
5918 daemon->have_dhparams =
true;
5924 "MHD HTTPS option %d passed to MHD but MHD_USE_TLS not set.\n"),
5942 _ (
"Setting priorities to `%s' failed: %s\n"),
5946 daemon->priority_cache =
NULL;
5954 "MHD HTTPS option %d passed to MHD but MHD_USE_TLS not set.\n"),
5959#if GNUTLS_VERSION_MAJOR < 3
5963 "MHD_OPTION_HTTPS_CERT_CALLBACK requires building MHD with GnuTLS >= 3.0.\n"));
5970 daemon->cert_callback =
pgcrf;
5975 "MHD HTTPS option %d passed to MHD but MHD_USE_TLS not set.\n"),
5981#if GNUTLS_VERSION_NUMBER < 0x030603
5985 "MHD_OPTION_HTTPS_CERT_CALLBACK2 requires building MHD with GnuTLS >= 3.6.3.\n"));
5992 daemon->cert_callback2 =
pgcrf2;
5997 "MHD HTTPS option %d passed to MHD but MHD_USE_TLS not set.\n"),
6005 daemon->digest_auth_rand_size =
va_arg (
ap,
6007 daemon->digest_auth_random =
va_arg (
ap,
6011 daemon->nonce_nc_size =
va_arg (
ap,
6020 _ (
"MHD_OPTION_LISTEN_SOCKET specified for daemon "
6021 "with MHD_USE_NO_LISTEN_SOCKET flag set.\n"));
6029#if defined(SO_DOMAIN) && defined(AF_UNIX)
6052 daemon->custom_error_log =
va_arg (
ap,
6054 daemon->custom_error_log_cls =
va_arg (
ap,
6058 _ (
"MHD_OPTION_EXTERNAL_LOGGER is not the first option "
6059 "specified for the daemon. Some messages may be "
6060 "printed by the standard MHD logger.\n"));
6069#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6071 daemon->thread_stack_size =
va_arg (
ap,
6077 daemon->fastopen_queue_size =
va_arg (
ap,
6083 _ (
"TCP fastopen is not supported on this platform.\n"));
6089 unsigned int) ? 1 : -1;
6102 _ (
"Flag MHD_USE_PEDANTIC_CHECKS is ignored because "
6103 "another behavior is specified by MHD_OPTION_STRICT_CLIENT.\n"));
6231#if GNUTLS_VERSION_MAJOR >= 3
6232 daemon->cred_callback =
va_arg (
ap,
6234 daemon->cred_callback_cls =
va_arg (
ap,
6240 "MHD HTTPS option %d passed to MHD compiled without GNUtls >= 3.\n"),
6257 daemon->disable_alpn = (
va_arg (
ap,
6265 _ (
"MHD HTTPS option %d passed to MHD " \
6266 "but MHD_USE_TLS not set.\n"),
6279 "MHD HTTPS option %d passed to MHD compiled without HTTPS support.\n"),
6286 "Invalid option %d! (Did you terminate the list with MHD_OPTION_END?).\n"),
6303#ifndef HAVE_MESSAGES
6307#ifdef USE_EPOLL_CREATE1
6316 _ (
"Call to epoll_create1 failed: %s\n"),
6321#if ! defined(USE_EPOLL_CREATE1)
6326 _ (
"Failed to set noninheritable mode on epoll FD.\n"));
6354 if (-1 == daemon->epoll_fd)
6356#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
6368 event.data.ptr = daemon;
6376 _ (
"Call to epoll_ctl failed: %s\n"),
6381 daemon->listen_socket_in_epoll =
true;
6395 _ (
"Call to epoll_ctl failed: %s\n"),
6447#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6464#ifndef EPOLL_SUPPORT
6468#ifndef HTTPS_SUPPORT
6478#ifdef UPGRADE_SUPPORT
6514#if defined(EPOLL_SUPPORT)
6516#elif defined(HAVE_POLL)
6525#if defined(EPOLL_SUPPORT)
6536 daemon->epoll_fd = -1;
6537#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
6538 daemon->epoll_upgrade_fd = -1;
6543 daemon->priority_cache =
NULL;
6558 daemon->
port = port;
6577 daemon->custom_error_log_cls =
stderr;
6579#ifndef MHD_WINSOCK_SOCKETS
6596#ifdef HAVE_LISTEN_SHUTDOWN
6602 daemon->digest_auth_rand_size = 0;
6603 daemon->digest_auth_random =
NULL;
6604 daemon->nonce_nc_size = 4;
6620 (
NULL != daemon->priority_cache) )
6633 "Warning: MHD_USE_THREAD_PER_CONNECTION must be used only with "
6634 "MHD_USE_INTERNAL_POLLING_THREAD. Flag MHD_USE_INTERNAL_POLLING_THREAD "
6635 "was added. Consider setting MHD_USE_INTERNAL_POLLING_THREAD explicitly.\n"));
6647 _ (
"Using debug build of libmicrohttpd.\n") );
6661 _ (
"Failed to create inter-thread communication channel: %s\n"),
6665 if (
NULL != daemon->priority_cache)
6678 "file descriptor for inter-thread communication channel exceeds maximum value.\n"));
6682 if (
NULL != daemon->priority_cache)
6691 if (daemon->nonce_nc_size > 0)
6694 /
sizeof(
struct MHD_NonceNc) != daemon->nonce_nc_size)
6698 _ (
"Specified value for NC_SIZE too large.\n"));
6708 if (
NULL == daemon->nnc)
6712 _ (
"Failed to allocate memory for nonce-nc map: %s\n"),
6724#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6729 _ (
"MHD failed to initialize nonce-nc mutex.\n"));
6743#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
6750 "MHD thread polling only works with MHD_USE_INTERNAL_POLLING_THREAD.\n"));
6774 _ (
"Failed to create socket for listening: %s\n"),
6783#ifndef MHD_WINSOCK_SOCKETS
6791 (
void *) &
on,
sizeof (
on)))
6795 _ (
"setsockopt failed: %s\n"),
6804#ifndef MHD_WINSOCK_SOCKETS
6810 (
void *) &
on,
sizeof (
on)))
6814 _ (
"setsockopt failed: %s\n"),
6824#if defined(MHD_WINSOCK_SOCKETS) || defined(SO_REUSEPORT)
6837 _ (
"setsockopt failed: %s\n"),
6848 "Cannot allow listening address reuse: SO_REUSEPORT not defined.\n"));
6861#if (defined(MHD_WINSOCK_SOCKETS) && defined(SO_EXCLUSIVEADDRUSE)) || \
6862 (defined(__sun) && defined(SO_EXCLBIND))
6875 _ (
"setsockopt failed: %s\n"),
6880#elif defined(MHD_WINSOCK_SOCKETS)
6884 "Cannot disallow listening address reuse: SO_EXCLUSIVEADDRUSE not defined.\n"));
6902#ifdef IN6ADDR_ANY_INIT
6910#ifdef IN6ADDR_ANY_INIT
6913#if HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN
6928#if HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
6952 _ (
"setsockopt failed: %s\n"),
6963 _ (
"Failed to bind to port %u: %s\n"),
6964 (
unsigned int) port,
6973 if (0 == daemon->fastopen_queue_size)
6978 (
const void *) &daemon->fastopen_queue_size,
6979 sizeof (daemon->fastopen_queue_size)))
6983 _ (
"setsockopt failed: %s\n"),
6994 _ (
"Failed to listen for connections: %s\n"),
7006#ifdef MHD_USE_GETSOCKNAME
7007 if ( (0 == daemon->
port) &&
7016#ifdef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN
7025 _ (
"Failed to get listen port number: %s\n"),
7029#ifdef MHD_POSIX_SOCKETS
7036 "Failed to get listen port number (`struct sockaddr_storage` too small!?).\n"));
7077 _ (
"Unknown address family!\n"));
7092 _ (
"Failed to set nonblocking mode on listening socket: %s\n"),
7117 _ (
"Listen socket descriptor (%d) is not " \
7118 "less than FD_SETSIZE (%d).\n"),
7141 "Combining MHD_USE_THREAD_PER_CONNECTION and MHD_USE_EPOLL is not supported.\n"));
7150#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
7155 _ (
"MHD failed to initialize IP connection limit mutex.\n"));
7165 _ (
"MHD failed to initialize IP connection limit mutex.\n"));
7167#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
7183 _ (
"Failed to initialize TLS support.\n"));
7187#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
7194#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
7202#ifdef HAVE_LISTEN_SHUTDOWN
7216 _ (
"Failed to initialise mutex.\n"));
7227 "MHD-listen" :
"MHD-single",
7228 daemon->thread_stack_size,
7236 _ (
"Failed to create a new thread because it would have " \
7237 "exceeded the system limit on the number of threads or " \
7238 "no system resources available.\n"));
7242 _ (
"Failed to create listen thread: %s\n"),
7284 d->worker_pool =
NULL;
7285#if defined(DAUTH_SUPPORT) && defined(MHD_USE_THREADS)
7287 memset (&
d->nnc_lock, -1,
sizeof(
d->nnc_lock));
7291 #ifdef HAVE_MESSAGES
7293 _ (
"Failed to initialise mutex.\n"));
7304 "Failed to create worker inter-thread communication channel: %s\n"),
7317 "File descriptor for worker inter-thread communication channel exceeds maximum value.\n"));
7327#ifdef HAVE_LISTEN_SHUTDOWN
7339 ++
d->connection_limit;
7355 _ (
"MHD failed to initialize cleanup connection mutex.\n"));
7366 daemon->thread_stack_size,
7374 _ (
"Failed to create a new pool thread because it would " \
7375 "have exceeded the system limit on the number of " \
7376 "threads or no system resources available.\n"));
7380 _ (
"Failed to create pool thread: %s\n"),
7400 _ (
"Failed to initialise mutex.\n"));
7409 daemon->https_key_password =
NULL;
7414#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
7443#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
7444 if (daemon->upgrade_fd_in_epoll)
7448 daemon->epoll_upgrade_fd,
7450 MHD_PANIC (
_ (
"Failed to remove FD from epoll set.\n"));
7451 daemon->upgrade_fd_in_epoll =
false;
7454 if (-1 != daemon->epoll_fd)
7455 close (daemon->epoll_fd);
7456#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
7457 if (-1 != daemon->epoll_upgrade_fd)
7458 close (daemon->epoll_upgrade_fd);
7463#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
7471 if (daemon->x509_cred)
7473 if (daemon->psk_cred)
7498#ifdef UPGRADE_SUPPORT
7501#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
7507#ifdef MHD_USE_THREADS
7515#ifdef MHD_USE_THREADS
7528#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
7539 urh->clean_ready =
true;
7556#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
7559#ifdef UPGRADE_SUPPORT
7569 "MHD_stop_daemon() called while we have suspended connections.\n"));
7573 (!
susp->urh->clean_ready) )
7574 shutdown (
susp->urh->app.socket,
7580 if (!
susp->urh->was_closed)
7583 "Initiated daemon shutdown while \"upgraded\" connection was not closed.\n"));
7585 susp->urh->was_closed =
true;
7592 susp->resuming =
true;
7602 "MHD_stop_daemon() called while we have suspended connections.\n"));
7603#if defined(UPGRADE_SUPPORT) && defined(HTTPS_SUPPORT)
7604#ifdef MHD_USE_THREADS
7624 MHD_PANIC (
_ (
"Failed to join a thread.\n"));
7636#if MHD_WINSOCK_SOCKETS
7641 "Failed to signal shutdown via inter-thread communication channel.\n"));
7645#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
7656 MHD_PANIC (
_ (
"Failed to join a thread.\n"));
7670#ifdef UPGRADE_SUPPORT
7686#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
7689 MHD_PANIC (
_ (
"Failed to join a thread.\n"));
7707#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
7714 MHD_PANIC (
_ (
"MHD_stop_daemon() was called twice."));
7724#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
7739 "Failed to signal shutdown via inter-thread communication channel.\n"));
7744#ifdef HAVE_LISTEN_SHUTDOWN
7759#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
7767#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
7777 "Failed to signal shutdown via inter-thread communication channel.\n"));
7781#ifdef HAVE_LISTEN_SHUTDOWN
7795 MHD_PANIC (
_ (
"Failed to join a thread.\n"));
7805#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
7813#if defined(UPGRADE_SUPPORT) && defined(HTTPS_SUPPORT)
7822 (-1 !=
daemon->epoll_fd) )
7824#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
7826 (-1 !=
daemon->epoll_upgrade_fd) )
7831#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
7845 if (
daemon->have_dhparams)
7848 daemon->have_dhparams =
false;
7862#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
7866#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
7911#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
7969#ifdef PACKAGE_VERSION
7972 static char ver[12] =
"\0\0\0\0\0\0\0\0\0\0\0";
8033#if defined(HTTPS_SUPPORT) && GNUTLS_VERSION_MAJOR >= 3
8039#if defined(HTTPS_SUPPORT) && GNUTLS_VERSION_NUMBER >= 0x030603
8051#if defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY)
8069#ifdef HAVE_LISTEN_SHUTDOWN
8075#ifdef _MHD_ITC_SOCKETPAIR
8099#ifdef HAVE_POSTPROCESSOR
8105#if defined(HTTPS_SUPPORT) && GNUTLS_VERSION_NUMBER >= 0x030111
8111#if defined(HAVE_PREAD64) || defined(_WIN32)
8113#elif defined(HAVE_PREAD)
8115#elif defined(HAVE_LSEEK64)
8121#if defined(MHD_USE_THREAD_NAME_)
8127#if defined(UPGRADE_SUPPORT)
8133#if defined(HAVE_PREAD64) || defined(HAVE_PREAD) || defined(_WIN32)
8139#ifdef MHD_USE_GETSOCKNAME
8145#if defined(MHD_SEND_SPIPE_SUPPRESS_POSSIBLE) || \
8146 ! defined(MHD_SEND_SPIPE_SUPPRESS_NEEDED)
8152#ifdef _MHD_HAVE_SENDFILE
8158#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
8169#ifdef MHD_HTTPS_REQUIRE_GCRYPT
8170#if defined(HTTPS_SUPPORT) && GCRYPT_VERSION_NUMBER < 0x010600
8171#if defined(MHD_USE_POSIX_THREADS)
8173#elif defined(MHD_W32_MUTEX_)
8233#if defined(MHD_WINSOCK_SOCKETS)
8240#if defined(MHD_WINSOCK_SOCKETS)
8242 MHD_PANIC (
_ (
"Failed to initialize winsock.\n"));
8245 MHD_PANIC (
_ (
"Winsock version 2.2 is not available.\n"));
8248#ifdef MHD_HTTPS_REQUIRE_GCRYPT
8249#if GCRYPT_VERSION_NUMBER < 0x010600
8250#if defined(MHD_USE_POSIX_THREADS)
8253 MHD_PANIC (
_ (
"Failed to initialise multithreading in libgcrypt.\n"));
8254#elif defined(MHD_W32_MUTEX_)
8257 MHD_PANIC (
_ (
"Failed to initialise multithreading in libgcrypt.\n"));
8263 "libgcrypt is too old. MHD was compiled for libgcrypt 1.6.0 or newer.\n"));
8289#if defined(MHD_WINSOCK_SOCKETS)
8297#ifdef _AUTOINIT_FUNCS_ARE_SUPPORTED
#define _SET_INIT_AND_DEINIT_FUNCS(FI, FD)
void MHD_connection_handle_write(struct MHD_Connection *connection)
void MHD_set_http_callbacks_(struct MHD_Connection *connection)
enum MHD_Result MHD_connection_handle_idle(struct MHD_Connection *connection)
void MHD_connection_handle_read(struct MHD_Connection *connection, bool socket_error)
Methods for managing connections.
#define MHD_connection_finish_forward_(conn)
static MHD_THRD_RTRN_TYPE_ MHD_THRD_CALL_SPEC_ thread_main_handle_connection(void *data)
void MHD_connection_mark_closed_(struct MHD_Connection *connection)
void MHD_connection_close_(struct MHD_Connection *connection, enum MHD_RequestTerminationCode rtc)
void MHD_set_https_callbacks(struct MHD_Connection *connection)
Methods for managing connections.
void MHD_update_last_activity_(struct MHD_Connection *connection)
void MHD_suspend_connection(struct MHD_Connection *connection)
static void close_all_connections(struct MHD_Daemon *daemon)
MHD_PanicCallback mhd_panic
static enum MHD_Result MHD_ip_limit_add(struct MHD_Daemon *daemon, const struct sockaddr *addr, socklen_t addrlen)
void MHD_resume_connection(struct MHD_Connection *connection)
void internal_suspend_connection_(struct MHD_Connection *connection)
static enum MHD_Result parse_options_va(struct MHD_Daemon *daemon, const struct sockaddr **servaddr, va_list ap)
static enum MHD_Result call_handlers(struct MHD_Connection *con, bool read_ready, bool write_ready, bool force_close)
static void MHD_ip_count_unlock(struct MHD_Daemon *daemon)
volatile int global_init_count
static enum MHD_Result MHD_poll(struct MHD_Daemon *daemon, int may_block)
void MHD_check_global_init_(void)
static void close_connection(struct MHD_Connection *pos)
static enum MHD_Result MHD_select(struct MHD_Daemon *daemon, int32_t millisec)
struct MHD_Daemon * MHD_get_master(struct MHD_Daemon *daemon)
static _MHD_NORETURN void mhd_panic_std(void *cls, const char *file, unsigned int line, const char *reason)
static int MHD_ip_addr_compare(const void *a1, const void *a2)
static void new_connections_list_process_(struct MHD_Daemon *daemon)
static void MHD_cleanup_connections(struct MHD_Daemon *daemon)
void(* VfprintfFunctionPointerType)(void *cls, const char *format, va_list va)
static enum MHD_Result MHD_accept_connection(struct MHD_Daemon *daemon)
static void MHD_ip_limit_del(struct MHD_Daemon *daemon, const struct sockaddr *addr, socklen_t addrlen)
#define MHD_MAX_CONNECTIONS_DEFAULT
static size_t unescape_wrapper(void *cls, struct MHD_Connection *connection, char *val)
static enum MHD_Result new_connection_process_(struct MHD_Daemon *daemon, struct MHD_Connection *connection)
static void MHD_ip_count_lock(struct MHD_Daemon *daemon)
static enum MHD_Result MHD_ip_addr_to_key(const struct sockaddr *addr, socklen_t addrlen, struct MHD_IPCount *key)
static enum MHD_Result parse_options(struct MHD_Daemon *daemon, const struct sockaddr **servaddr,...)
static struct MHD_Connection * new_connection_prepare_(struct MHD_Daemon *daemon, MHD_socket client_socket, const struct sockaddr *addr, socklen_t addrlen, bool external_add, bool non_blck, bool sk_spipe_supprs, enum MHD_tristate sk_is_nonip)
static enum MHD_Result resume_suspended_connections(struct MHD_Daemon *daemon)
#define MHD_POOL_SIZE_DEFAULT
static enum MHD_Result internal_add_connection(struct MHD_Daemon *daemon, MHD_socket client_socket, const struct sockaddr *addr, socklen_t addrlen, bool external_add, bool non_blck, bool sk_spipe_supprs, enum MHD_tristate sk_is_nonip)
_MHD_EXTERN void MHD_free(void *ptr)
static enum MHD_Result internal_get_fdset2(struct MHD_Daemon *daemon, fd_set *read_fd_set, fd_set *write_fd_set, fd_set *except_fd_set, MHD_socket *max_fd, unsigned int fd_setsize)
static enum MHD_Result internal_run_from_select(struct MHD_Daemon *daemon, const fd_set *read_fd_set, const fd_set *write_fd_set, const fd_set *except_fd_set)
static MHD_THRD_RTRN_TYPE_ MHD_THRD_CALL_SPEC_ MHD_polling_thread(void *cls)
_MHD_EXTERN struct MHD_Daemon * MHD_start_daemon(unsigned int flags, uint16_t port, MHD_AcceptPolicyCallback apc, void *apc_cls, MHD_AccessHandlerCallback dh, void *dh_cls,...)
_MHD_EXTERN void MHD_stop_daemon(struct MHD_Daemon *daemon)
_MHD_EXTERN enum MHD_Result MHD_run_from_select(struct MHD_Daemon *daemon, const fd_set *read_fd_set, const fd_set *write_fd_set, const fd_set *except_fd_set)
_MHD_EXTERN struct MHD_Daemon * MHD_start_daemon_va(unsigned int flags, uint16_t port, MHD_AcceptPolicyCallback apc, void *apc_cls, MHD_AccessHandlerCallback dh, void *dh_cls, va_list ap)
_MHD_EXTERN enum MHD_Result MHD_run(struct MHD_Daemon *daemon)
_MHD_EXTERN enum MHD_Result MHD_get_timeout(struct MHD_Daemon *daemon, MHD_UNSIGNED_LONG_LONG *timeout)
#define MHD_get_fdset(daemon, read_fd_set, write_fd_set, except_fd_set, max_fd)
_MHD_EXTERN enum MHD_Result MHD_run_wait(struct MHD_Daemon *daemon, int32_t millisec)
_MHD_EXTERN enum MHD_Result MHD_get_fdset2(struct MHD_Daemon *daemon, fd_set *read_fd_set, fd_set *write_fd_set, fd_set *except_fd_set, MHD_socket *max_fd, unsigned int fd_setsize)
void(* MHD_PanicCallback)(void *cls, const char *file, unsigned int line, const char *reason)
_MHD_EXTERN void MHD_set_panic_func(MHD_PanicCallback cb, void *cls)
void(* MHD_NotifyConnectionCallback)(void *cls, struct MHD_Connection *connection, void **socket_context, enum MHD_ConnectionNotificationCode toe)
void(* MHD_RequestCompletedCallback)(void *cls, struct MHD_Connection *connection, void **con_cls, enum MHD_RequestTerminationCode toe)
@ MHD_CONNECTION_NOTIFY_STARTED
@ MHD_CONNECTION_NOTIFY_CLOSED
@ MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN
@ MHD_REQUEST_TERMINATED_COMPLETED_OK
@ MHD_REQUEST_TERMINATED_WITH_ERROR
_MHD_EXTERN void MHD_destroy_response(struct MHD_Response *response)
_MHD_EXTERN const union MHD_DaemonInfo * MHD_get_daemon_info(struct MHD_Daemon *daemon, enum MHD_DaemonInfoType info_type,...)
_MHD_EXTERN MHD_socket MHD_quiesce_daemon(struct MHD_Daemon *daemon)
_MHD_EXTERN enum MHD_Result MHD_add_connection(struct MHD_Daemon *daemon, MHD_socket client_socket, const struct sockaddr *addr, socklen_t addrlen)
_MHD_EXTERN enum MHD_Result MHD_is_feature_supported(enum MHD_FEATURE feature)
_MHD_EXTERN uint32_t MHD_get_version_bin(void)
_MHD_EXTERN const char * MHD_get_version(void)
#define XDLL_insert(head, tail, element)
@ MHD_EPOLL_STATE_SUSPENDED
@ MHD_EPOLL_STATE_IN_EREADY_EDLL
@ MHD_EPOLL_STATE_READ_READY
@ MHD_EPOLL_STATE_IN_EPOLL_SET
@ MHD_EPOLL_STATE_WRITE_READY
#define DLL_insert(head, tail, element)
#define EDLL_insert(head, tail, element)
#define EDLL_remove(head, tail, element)
#define XDLL_remove(head, tail, element)
#define DLL_remove(head, tail, element)
void MHD_pool_destroy(struct MemoryPool *pool)
struct MemoryPool * MHD_pool_create(size_t max)
void * MHD_calloc_(size_t nelem, size_t elsize)
#define MHD_strerror_(errnum)
#define MHD_ITC_IS_INVALID_(itc)
#define MHD_itc_destroy_chk_(itc)
#define TIMEVAL_TV_SEC_MAX
#define MHD_mutex_unlock_chk_(pmutex)
#define MHD_mutex_destroy_chk_(pmutex)
#define MHD_mutex_lock_chk_(pmutex)
void MHD_monotonic_sec_counter_finish(void)
void MHD_monotonic_sec_counter_init(void)
int MHD_add_to_fd_set_(MHD_socket fd, fd_set *set, MHD_socket *max_fd, unsigned int fd_setsize)
int MHD_socket_noninheritable_(MHD_socket sock)
int MHD_socket_nonblocking_(MHD_socket sock)
MHD_socket MHD_socket_create_listen_(int pf)
#define MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_(err)
#define MHD_SCKT_ERR_IS_(err, code)
#define MHD_socket_close_(fd)
#define MHD_SCKT_ERR_IS_EAGAIN_(err)
#define MHD_SCKT_ERR_IS_LOW_RESOURCES_(err)
#define _MHD_SYS_DEFAULT_FD_SETSIZE
#define MHD_socket_strerr_(err)
#define MHD_socket_last_strerr_()
#define MHD_socket_get_error_()
#define MHD_socket_close_chk_(fd)
#define MHD_SCKT_ERR_IS_EINTR_(err)
#define MHD_socket_fset_error_(err)
#define MHD_SCKT_SEND_MAX_SIZE_
#define MHD_recv_(s, b, l)
#define MHD_send_(s, b, l)
#define MHD_SCKT_LAST_ERR_IS_(code)
#define MHD_SYS_select_(n, r, w, e, t)
#define MHD_SCKT_FD_FITS_FDSET_(fd, pset)
#define MHD_STATICSTR_LEN_(macro)
#define MHD_create_named_thread_(t, n, s, r, a)
void * tfind(const void *vkey, void *const *vrootp, int(*compar)(const void *, const void *))
void * tdelete(const void *__restrict vkey, void **__restrict vrootp, int(*compar)(const void *, const void *))
void * tsearch(const void *vkey, void **vrootp, int(*compar)(const void *, const void *))
void MHD_send_init_static_vars_(void)
Declarations of send() wrappers.
MHD internal shared structures.
@ MHD_CONNECTION_HEADERS_SENDING
@ MHD_CONNECTION_NORMAL_BODY_READY
@ MHD_CONNECTION_CHUNKED_BODY_READY
@ MHD_EVENT_LOOP_INFO_READ
@ MHD_EVENT_LOOP_INFO_WRITE
@ MHD_EVENT_LOOP_INFO_CLEANUP
@ MHD_EVENT_LOOP_INFO_BLOCK
void *(* LogCallback)(void *cls, const char *uri, struct MHD_Connection *con)
#define MHD_TEST_ALLOW_SUSPEND_RESUME
size_t(* UnescapeCallback)(void *cls, struct MHD_Connection *conn, char *uri)
void MHD_init_mem_pools_(void)
memory pool; mostly used for efficient (de)allocation for each connection and bounding memory use for...
Header for platform missing functions.
Header for platform-independent inter-thread communication.
limits values definitions
#define MHD_mutex_destroy_(ignore)
#define MHD_mutex_unlock_(ignore)
#define MHD_mutex_lock_(ignore)
#define MHD_mutex_init_(ignore)
uint64_t MHD_monotonic_msec_counter(void)
internal monotonic clock functions implementations
#define SOCK_NONBLOCK_OR_ZERO
#define SOCK_NOSIGPIPE_OR_ZERO
#define SOCK_CLOEXEC_OR_ZERO
@ MHD_FEATURE_POSTPROCESSOR
@ MHD_FEATURE_SHUTDOWN_LISTEN_SOCKET
@ MHD_FEATURE_AUTODETECT_BIND_PORT
@ MHD_FEATURE_HTTPS_CERT_CALLBACK
@ MHD_FEATURE_DIGEST_AUTH
@ MHD_FEATURE_THREAD_NAMES
@ MHD_FEATURE_HTTPS_KEY_PASSWORD
@ MHD_FEATURE_AUTOSUPPRESS_SIGPIPE
@ MHD_FEATURE_RESPONSES_SHARED_FD
@ MHD_FEATURE_TCP_FASTOPEN
@ MHD_FEATURE_HTTPS_CERT_CALLBACK2
@ MHD_OPTION_CONNECTION_MEMORY_INCREMENT
@ MHD_OPTION_HTTPS_CRED_TYPE
@ MHD_OPTION_URI_LOG_CALLBACK
@ MHD_OPTION_HTTPS_CERT_CALLBACK2
@ MHD_OPTION_SIGPIPE_HANDLED_BY_APP
@ MHD_OPTION_UNESCAPE_CALLBACK
@ MHD_OPTION_EXTERNAL_LOGGER
@ MHD_OPTION_LISTEN_BACKLOG_SIZE
@ MHD_OPTION_HTTPS_PRIORITIES
@ MHD_OPTION_HTTPS_MEM_DHPARAMS
@ MHD_OPTION_NOTIFY_CONNECTION
@ MHD_OPTION_LISTENING_ADDRESS_REUSE
@ MHD_OPTION_THREAD_POOL_SIZE
@ MHD_OPTION_CONNECTION_LIMIT
@ MHD_OPTION_PER_IP_CONNECTION_LIMIT
@ MHD_OPTION_TCP_FASTOPEN_QUEUE_SIZE
@ MHD_OPTION_HTTPS_MEM_CERT
@ MHD_OPTION_SERVER_INSANITY
@ MHD_OPTION_LISTEN_SOCKET
@ MHD_OPTION_HTTPS_MEM_KEY
@ MHD_OPTION_DIGEST_AUTH_RANDOM
@ MHD_OPTION_HTTPS_KEY_PASSWORD
@ MHD_OPTION_NONCE_NC_SIZE
@ MHD_OPTION_CONNECTION_MEMORY_LIMIT
@ MHD_OPTION_THREAD_STACK_SIZE
@ MHD_OPTION_STRICT_FOR_CLIENT
@ MHD_OPTION_CONNECTION_TIMEOUT
@ MHD_OPTION_GNUTLS_PSK_CRED_HANDLER
@ MHD_OPTION_HTTPS_MEM_TRUST
@ MHD_OPTION_HTTPS_CERT_CALLBACK
@ MHD_OPTION_NOTIFY_COMPLETED
enum MHD_Result(* MHD_AcceptPolicyCallback)(void *cls, const struct sockaddr *addr, socklen_t addrlen)
#define MHD_UNSIGNED_LONG_LONG
_MHD_EXTERN size_t MHD_http_unescape(char *val)
#define MHD_INVALID_SOCKET
enum MHD_Result(* MHD_AccessHandlerCallback)(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls)
int(* MHD_PskServerCredentialsCallback)(void *cls, const struct MHD_Connection *connection, const char *username, void **psk, size_t *psk_size)
@ MHD_DAEMON_INFO_MAC_KEY_SIZE
@ MHD_DAEMON_INFO_BIND_PORT
@ MHD_DAEMON_INFO_EPOLL_FD
@ MHD_DAEMON_INFO_KEY_SIZE
@ MHD_DAEMON_INFO_CURRENT_CONNECTIONS
@ MHD_DAEMON_INFO_LISTEN_FD
MHD_FLAG
Flags for the struct MHD_Daemon.
@ MHD_ALLOW_SUSPEND_RESUME
@ MHD_USE_THREAD_PER_CONNECTION
@ MHD_USE_POST_HANDSHAKE_AUTH_SUPPORT
@ MHD_USE_INSECURE_TLS_EARLY_DATA
@ MHD_USE_NO_LISTEN_SOCKET
@ MHD_USE_PEDANTIC_CHECKS
@ MHD_USE_INTERNAL_POLLING_THREAD
Methods for managing response objects.
enum MHD_tristate sk_nodelay
struct MHD_Connection * prevX
enum MHD_ConnectionEventLoopInfo event_loop_info
enum MHD_tristate is_nonip
struct MHD_Response * response
struct MHD_Connection * next
struct sockaddr_storage addr
size_t read_buffer_offset
struct MHD_Connection * prev
MHD_thread_handle_ID_ pid
struct MHD_Connection * nextX
enum MHD_CONNECTION_STATE state
struct MHD_Daemon * daemon
uint64_t connection_timeout_ms
enum MHD_tristate sk_corked
MHD_NotifyConnectionCallback notify_connection
MHD_AccessHandlerCallback default_handler
LogCallback uri_log_callback
bool data_already_pending
MHD_mutex_ per_ip_connection_mutex
void * per_ip_connection_count
struct MHD_Connection * new_connections_tail
unsigned int connection_limit
void * unescape_callback_cls
MHD_mutex_ cleanup_connection_mutex
enum MHD_DisableSanityCheck insanity_level
struct MHD_Connection * connections_head
unsigned int listen_backlog_size
MHD_RequestCompletedCallback notify_completed
unsigned int worker_pool_size
int listening_address_reuse
uint64_t connection_timeout_ms
unsigned int per_ip_connection_limit
struct MHD_Connection * manual_timeout_tail
void * notify_connection_cls
UnescapeCallback unescape_callback
void * notify_completed_cls
struct MHD_Connection * cleanup_tail
struct MHD_Daemon * worker_pool
struct MHD_Connection * new_connections_head
MHD_thread_handle_ID_ pid
struct MHD_Connection * manual_timeout_head
enum MHD_tristate listen_is_unix
void * default_handler_cls
struct MHD_Connection * suspended_connections_tail
MHD_AcceptPolicyCallback apc
struct MHD_Connection * cleanup_head
struct MHD_Daemon * master
struct MHD_Connection * normal_timeout_head
struct MHD_Connection * normal_timeout_tail
void * uri_log_callback_cls
struct MHD_Connection * suspended_connections_head
struct MHD_Connection * connections_tail