• Home
  • Raw
  • Download

Lines Matching refs:daemon

169 MHD_get_master (struct MHD_Daemon *daemon)  in MHD_get_master()  argument
171 while (NULL != daemon->master) in MHD_get_master()
172 daemon = daemon->master; in MHD_get_master()
173 return daemon; in MHD_get_master()
217 MHD_ip_count_lock (struct MHD_Daemon *daemon) in MHD_ip_count_lock() argument
219 if (MHD_YES != MHD_mutex_lock_(&daemon->per_ip_connection_mutex)) in MHD_ip_count_lock()
232 MHD_ip_count_unlock (struct MHD_Daemon *daemon) in MHD_ip_count_unlock() argument
234 if (MHD_YES != MHD_mutex_unlock_(&daemon->per_ip_connection_mutex)) in MHD_ip_count_unlock()
307 MHD_ip_limit_add (struct MHD_Daemon *daemon, in MHD_ip_limit_add() argument
316 daemon = MHD_get_master (daemon); in MHD_ip_limit_add()
318 if (0 == daemon->per_ip_connection_limit) in MHD_ip_limit_add()
331 MHD_ip_count_lock (daemon); in MHD_ip_limit_add()
335 &daemon->per_ip_connection_count, in MHD_ip_limit_add()
339 MHD_DLOG (daemon, in MHD_ip_limit_add()
342 MHD_ip_count_unlock (daemon); in MHD_ip_limit_add()
353 result = (key->count < daemon->per_ip_connection_limit); in MHD_ip_limit_add()
357 MHD_ip_count_unlock (daemon); in MHD_ip_limit_add()
371 MHD_ip_limit_del (struct MHD_Daemon *daemon, in MHD_ip_limit_del() argument
379 daemon = MHD_get_master (daemon); in MHD_ip_limit_del()
381 if (0 == daemon->per_ip_connection_limit) in MHD_ip_limit_del()
387 MHD_ip_count_lock (daemon); in MHD_ip_limit_del()
391 &daemon->per_ip_connection_count, in MHD_ip_limit_del()
408 &daemon->per_ip_connection_count, in MHD_ip_limit_del()
413 MHD_ip_count_unlock (daemon); in MHD_ip_limit_del()
519 connection->daemon->num_tls_read_ready--; in recv_tls_adapter()
542 connection->daemon->num_tls_read_ready++; in recv_tls_adapter()
591 MHD_TLS_init (struct MHD_Daemon *daemon) in MHD_TLS_init() argument
594 daemon->tls_context = SSL_CTX_new (TLSv1_2_server_method()); in MHD_TLS_init()
595 if (NULL == daemon->tls_context) in MHD_TLS_init()
597 if (NULL != daemon->https_mem_trust) in MHD_TLS_init()
600 BIO* mem_bio = BIO_new_mem_buf ((void*)daemon->https_mem_trust, -1); in MHD_TLS_init()
605 ret = SSL_CTX_add_client_CA (daemon->tls_context, x509); in MHD_TLS_init()
610 MHD_DLOG (daemon, in MHD_TLS_init()
617 if (NULL != daemon->https_mem_dhparams) in MHD_TLS_init()
620 BIO* mem_bio = BIO_new_mem_buf ((void*)daemon->https_mem_dhparams, -1); in MHD_TLS_init()
625 ret = SSL_CTX_set_tmp_dh (daemon->tls_context, dh); in MHD_TLS_init()
630 MHD_DLOG (daemon, in MHD_TLS_init()
638 if ( (NULL != daemon->https_mem_cert) && in MHD_TLS_init()
639 (NULL != daemon->https_mem_key) ) in MHD_TLS_init()
642 BIO* mem_bio = BIO_new_mem_buf ((void*)daemon->https_mem_key, -1); in MHD_TLS_init()
644 (void*)daemon->https_key_password); in MHD_TLS_init()
648 ret = SSL_CTX_use_PrivateKey (daemon->tls_context, key); in MHD_TLS_init()
653 MHD_DLOG (daemon, in MHD_TLS_init()
659 mem_bio = BIO_new_mem_buf ((void*)daemon->https_mem_cert, -1); in MHD_TLS_init()
664 ret = SSL_CTX_use_certificate (daemon->tls_context, x509); in MHD_TLS_init()
669 MHD_DLOG (daemon, in MHD_TLS_init()
674 if (1 != SSL_CTX_check_private_key (daemon->tls_context)) in MHD_TLS_init()
677 MHD_DLOG (daemon, in MHD_TLS_init()
686 MHD_DLOG (daemon, in MHD_TLS_init()
691 if (NULL != daemon->https_mem_cipher) in MHD_TLS_init()
693 ret = SSL_CTX_set_cipher_list (daemon->tls_context, in MHD_TLS_init()
694 daemon->https_mem_cipher); in MHD_TLS_init()
698 MHD_DLOG (daemon, in MHD_TLS_init()
706 ret = SSL_CTX_set_cipher_list (daemon->tls_context, in MHD_TLS_init()
711 MHD_DLOG (daemon, in MHD_TLS_init()
721 MHD_TLS_deinit (struct MHD_Daemon *daemon) in MHD_TLS_deinit() argument
723 SSL_CTX_free (daemon->tls_context); in MHD_TLS_deinit()
788 MHD_get_fdset (struct MHD_Daemon *daemon, in MHD_get_fdset() argument
794 return MHD_get_fdset2(daemon, read_fd_set, in MHD_get_fdset()
821 MHD_get_fdset2 (struct MHD_Daemon *daemon, in MHD_get_fdset2() argument
830 if ( (NULL == daemon) in MHD_get_fdset2()
833 || (MHD_YES == daemon->shutdown) in MHD_get_fdset2()
834 || (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) in MHD_get_fdset2()
835 || (0 != (daemon->options & MHD_USE_POLL))) in MHD_get_fdset2()
838 if (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) in MHD_get_fdset2()
843 return add_to_fd_set (daemon->epoll_fd, read_fd_set, max_fd, fd_setsize); in MHD_get_fdset2()
846 if (MHD_INVALID_SOCKET != daemon->socket_fd && in MHD_get_fdset2()
847 MHD_YES != add_to_fd_set (daemon->socket_fd, read_fd_set, max_fd, fd_setsize)) in MHD_get_fdset2()
850 for (pos = daemon->connections_head; NULL != pos; pos = pos->next) in MHD_get_fdset2()
878 MHD_DLOG (daemon, in MHD_get_fdset2()
907 MHD_pipe spipe = con->daemon->wpipe[0]; in MHD_handle_connection()
920 timeout = con->daemon->connection_timeout; in MHD_handle_connection()
921 while ( (MHD_YES != con->daemon->shutdown) && in MHD_handle_connection()
944 if (0 == (con->daemon->options & MHD_USE_POLL)) in MHD_handle_connection()
991 MHD_DLOG (con->daemon, in MHD_handle_connection()
1003 MHD_DLOG (con->daemon, in MHD_handle_connection()
1076 MHD_DLOG (con->daemon, in MHD_handle_connection()
1107 MHD_DLOG (con->daemon, in MHD_handle_connection()
1123 if (NULL != con->daemon->notify_connection) in MHD_handle_connection()
1124 con->daemon->notify_connection (con->daemon->notify_connection_cls, in MHD_handle_connection()
1192 if (0 != (connection->daemon->options & MHD_USE_SSL)) in send_param_adapter()
1267 const struct MHD_Daemon *daemon, in create_thread() argument
1276 if (0 != daemon->thread_stack_size) in create_thread()
1280 if (0 != (ret = pthread_attr_setstacksize (&attr, daemon->thread_stack_size))) in create_thread()
1296 if (0 != daemon->thread_stack_size) in create_thread()
1301 MHD_DLOG (daemon, in create_thread()
1308 *thread = (HANDLE)_beginthreadex(NULL, (unsigned)daemon->thread_stack_size, start_routine, in create_thread()
1347 internal_add_connection (struct MHD_Daemon *daemon, in internal_add_connection() argument
1362 if (NULL != daemon->worker_pool) in internal_add_connection()
1367 for (i=0;i<daemon->worker_pool_size;i++) in internal_add_connection()
1369 worker = &daemon->worker_pool[(i + client_socket) % daemon->worker_pool_size]; in internal_add_connection()
1387 (0 == (daemon->options & (MHD_USE_POLL | MHD_USE_EPOLL_LINUX_ONLY))) ) in internal_add_connection()
1390 MHD_DLOG (daemon, in internal_add_connection()
1407 MHD_DLOG (daemon, in internal_add_connection()
1412 if ( (daemon->connections == daemon->connection_limit) || in internal_add_connection()
1413 (MHD_NO == MHD_ip_limit_add (daemon, addr, addrlen)) ) in internal_add_connection()
1417 MHD_DLOG (daemon, in internal_add_connection()
1429 if ( (NULL != daemon->apc) && in internal_add_connection()
1430 (MHD_NO == daemon->apc (daemon->apc_cls, in internal_add_connection()
1435 MHD_DLOG (daemon, in internal_add_connection()
1441 MHD_ip_limit_del (daemon, addr, addrlen); in internal_add_connection()
1462 MHD_DLOG (daemon, in internal_add_connection()
1468 MHD_ip_limit_del (daemon, addr, addrlen); in internal_add_connection()
1475 connection->pool = MHD_pool_create (daemon->pool_size); in internal_add_connection()
1479 MHD_DLOG (daemon, in internal_add_connection()
1485 MHD_ip_limit_del (daemon, addr, addrlen); in internal_add_connection()
1493 connection->connection_timeout = daemon->connection_timeout; in internal_add_connection()
1498 MHD_DLOG (daemon, in internal_add_connection()
1504 MHD_ip_limit_del (daemon, addr, addrlen); in internal_add_connection()
1513 connection->daemon = daemon; in internal_add_connection()
1521 if (0 == (connection->daemon->options & MHD_USE_EPOLL_TURBO)) in internal_add_connection()
1528 if (0 != (daemon->options & MHD_USE_SSL)) in internal_add_connection()
1538 MHD_DLOG (daemon, in internal_add_connection()
1548 MHD_DLOG (daemon, in internal_add_connection()
1558 if (0 != (daemon->options & MHD_USE_SSL)) in internal_add_connection()
1564 connection->tls_session = SSL_new (daemon->tls_context); in internal_add_connection()
1576 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && in internal_add_connection()
1577 (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) ) in internal_add_connection()
1579 XDLL_insert (daemon->normal_timeout_head, in internal_add_connection()
1580 daemon->normal_timeout_tail, in internal_add_connection()
1582 DLL_insert (daemon->connections_head, in internal_add_connection()
1583 daemon->connections_tail, in internal_add_connection()
1585 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && in internal_add_connection()
1586 (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) ) in internal_add_connection()
1589 if (NULL != daemon->notify_connection) in internal_add_connection()
1590 daemon->notify_connection (daemon->notify_connection_cls, in internal_add_connection()
1596 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) in internal_add_connection()
1599 daemon, in internal_add_connection()
1606 MHD_DLOG (daemon, in internal_add_connection()
1615 (MHD_INVALID_PIPE_ != daemon->wpipe[1]) && in internal_add_connection()
1616 (1 != MHD_pipe_write_ (daemon->wpipe[1], "n", 1)) ) in internal_add_connection()
1619 MHD_DLOG (daemon, in internal_add_connection()
1624 if (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) in internal_add_connection()
1626 if (0 == (daemon->options & MHD_USE_EPOLL_TURBO)) in internal_add_connection()
1632 if (0 != epoll_ctl (daemon->epoll_fd, in internal_add_connection()
1639 MHD_DLOG (daemon, in internal_add_connection()
1651 EDLL_insert (daemon->eready_head, in internal_add_connection()
1652 daemon->eready_tail, in internal_add_connection()
1657 daemon->connections++; in internal_add_connection()
1660 if (NULL != daemon->notify_connection) in internal_add_connection()
1661 daemon->notify_connection (daemon->notify_connection_cls, in internal_add_connection()
1667 MHD_ip_limit_del (daemon, addr, addrlen); in internal_add_connection()
1668 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && in internal_add_connection()
1669 (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) ) in internal_add_connection()
1671 DLL_remove (daemon->connections_head, in internal_add_connection()
1672 daemon->connections_tail, in internal_add_connection()
1674 XDLL_remove (daemon->normal_timeout_head, in internal_add_connection()
1675 daemon->normal_timeout_tail, in internal_add_connection()
1677 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && in internal_add_connection()
1678 (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) ) in internal_add_connection()
1720 struct MHD_Daemon *daemon; in MHD_suspend_connection() local
1722 daemon = connection->daemon; in MHD_suspend_connection()
1723 if (MHD_USE_SUSPEND_RESUME != (daemon->options & MHD_USE_SUSPEND_RESUME)) in MHD_suspend_connection()
1725 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && in MHD_suspend_connection()
1726 (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) ) in MHD_suspend_connection()
1728 DLL_remove (daemon->connections_head, in MHD_suspend_connection()
1729 daemon->connections_tail, in MHD_suspend_connection()
1731 DLL_insert (daemon->suspended_connections_head, in MHD_suspend_connection()
1732 daemon->suspended_connections_tail, in MHD_suspend_connection()
1734 if (connection->connection_timeout == daemon->connection_timeout) in MHD_suspend_connection()
1735 XDLL_remove (daemon->normal_timeout_head, in MHD_suspend_connection()
1736 daemon->normal_timeout_tail, in MHD_suspend_connection()
1739 XDLL_remove (daemon->manual_timeout_head, in MHD_suspend_connection()
1740 daemon->manual_timeout_tail, in MHD_suspend_connection()
1743 if (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) in MHD_suspend_connection()
1747 EDLL_remove (daemon->eready_head, in MHD_suspend_connection()
1748 daemon->eready_tail, in MHD_suspend_connection()
1754 if (0 != epoll_ctl (daemon->epoll_fd, in MHD_suspend_connection()
1765 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && in MHD_suspend_connection()
1766 (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) ) in MHD_suspend_connection()
1782 struct MHD_Daemon *daemon; in MHD_resume_connection() local
1784 daemon = connection->daemon; in MHD_resume_connection()
1785 if (MHD_USE_SUSPEND_RESUME != (daemon->options & MHD_USE_SUSPEND_RESUME)) in MHD_resume_connection()
1787 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && in MHD_resume_connection()
1788 (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) ) in MHD_resume_connection()
1791 daemon->resuming = MHD_YES; in MHD_resume_connection()
1792 if ( (MHD_INVALID_PIPE_ != daemon->wpipe[1]) && in MHD_resume_connection()
1793 (1 != MHD_pipe_write_ (daemon->wpipe[1], "r", 1)) ) in MHD_resume_connection()
1796 MHD_DLOG (daemon, in MHD_resume_connection()
1800 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && in MHD_resume_connection()
1801 (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) ) in MHD_resume_connection()
1814 resume_suspended_connections (struct MHD_Daemon *daemon) in resume_suspended_connections() argument
1821 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && in resume_suspended_connections()
1822 (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) ) in resume_suspended_connections()
1824 if (MHD_YES == daemon->resuming) in resume_suspended_connections()
1825 next = daemon->suspended_connections_head; in resume_suspended_connections()
1833 DLL_remove (daemon->suspended_connections_head, in resume_suspended_connections()
1834 daemon->suspended_connections_tail, in resume_suspended_connections()
1836 DLL_insert (daemon->connections_head, in resume_suspended_connections()
1837 daemon->connections_tail, in resume_suspended_connections()
1839 if (pos->connection_timeout == daemon->connection_timeout) in resume_suspended_connections()
1840 XDLL_insert (daemon->normal_timeout_head, in resume_suspended_connections()
1841 daemon->normal_timeout_tail, in resume_suspended_connections()
1844 XDLL_insert (daemon->manual_timeout_head, in resume_suspended_connections()
1845 daemon->manual_timeout_tail, in resume_suspended_connections()
1848 if (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) in resume_suspended_connections()
1854 EDLL_insert (daemon->eready_head, in resume_suspended_connections()
1855 daemon->eready_tail, in resume_suspended_connections()
1864 daemon->resuming = MHD_NO; in resume_suspended_connections()
1865 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && in resume_suspended_connections()
1866 (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) ) in resume_suspended_connections()
1879 make_nonblocking_noninheritable (struct MHD_Daemon *daemon, in make_nonblocking_noninheritable() argument
1889 MHD_DLOG (daemon, in make_nonblocking_noninheritable()
1899 MHD_DLOG (daemon, in make_nonblocking_noninheritable()
1910 if (0 == (daemon->options & MHD_USE_SSL)) in make_nonblocking_noninheritable()
1919 MHD_DLOG (daemon, in make_nonblocking_noninheritable()
1958 MHD_add_connection (struct MHD_Daemon *daemon, in MHD_add_connection() argument
1963 make_nonblocking_noninheritable (daemon, in MHD_add_connection()
1965 return internal_add_connection (daemon, in MHD_add_connection()
1985 MHD_accept_connection (struct MHD_Daemon *daemon) in MHD_accept_connection() argument
2000 if (MHD_INVALID_SOCKET == (fd = daemon->socket_fd)) in MHD_accept_connection()
2008 if (0 == (daemon->options & MHD_USE_SSL)) in MHD_accept_connection()
2022 (MHD_INVALID_SOCKET == daemon->socket_fd) ) in MHD_accept_connection()
2025 MHD_DLOG (daemon, in MHD_accept_connection()
2038 make_nonblocking_noninheritable (daemon, s); in MHD_accept_connection()
2042 MHD_DLOG (daemon, in MHD_accept_connection()
2047 (void) internal_add_connection (daemon, s, in MHD_accept_connection()
2062 MHD_cleanup_connections (struct MHD_Daemon *daemon) in MHD_cleanup_connections() argument
2066 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && in MHD_cleanup_connections()
2067 (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) ) in MHD_cleanup_connections()
2069 while (NULL != (pos = daemon->cleanup_head)) in MHD_cleanup_connections()
2071 DLL_remove (daemon->cleanup_head, in MHD_cleanup_connections()
2072 daemon->cleanup_tail, in MHD_cleanup_connections()
2074 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && in MHD_cleanup_connections()
2087 if (NULL != daemon->notify_connection) in MHD_cleanup_connections()
2088 daemon->notify_connection (daemon->notify_connection_cls, in MHD_cleanup_connections()
2092 MHD_ip_limit_del (daemon, pos->addr, pos->addr_len); in MHD_cleanup_connections()
2096 EDLL_remove (daemon->eready_head, in MHD_cleanup_connections()
2097 daemon->eready_tail, in MHD_cleanup_connections()
2101 if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) && in MHD_cleanup_connections()
2102 (MHD_INVALID_SOCKET != daemon->epoll_fd) && in MHD_cleanup_connections()
2111 if (0 != epoll_ctl (daemon->epoll_fd, in MHD_cleanup_connections()
2135 daemon->connections--; in MHD_cleanup_connections()
2137 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && in MHD_cleanup_connections()
2138 (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) ) in MHD_cleanup_connections()
2158 MHD_get_timeout (struct MHD_Daemon *daemon, in MHD_get_timeout() argument
2166 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) in MHD_get_timeout()
2169 MHD_DLOG (daemon, in MHD_get_timeout()
2176 if (0 != daemon->num_tls_read_ready) in MHD_get_timeout()
2187 for (pos = daemon->manual_timeout_head; NULL != pos; pos = pos->nextX) in MHD_get_timeout()
2195 if ( (0 != (daemon->options & MHD_USE_SSL)) && in MHD_get_timeout()
2203 pos = daemon->normal_timeout_head; in MHD_get_timeout()
2211 if ( (0 != (daemon->options & MHD_USE_SSL)) && in MHD_get_timeout()
2249 MHD_run_from_select (struct MHD_Daemon *daemon, in MHD_run_from_select() argument
2260 if (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) in MHD_run_from_select()
2264 if (daemon->epoll_fd >= FD_SETSIZE) in MHD_run_from_select()
2266 if (FD_ISSET (daemon->epoll_fd, read_fd_set)) in MHD_run_from_select()
2267 return MHD_run (daemon); in MHD_run_from_select()
2273 if ( (MHD_INVALID_SOCKET != (ds = daemon->socket_fd)) && in MHD_run_from_select()
2275 (void) MHD_accept_connection (daemon); in MHD_run_from_select()
2277 if ( (MHD_INVALID_PIPE_ != daemon->wpipe[0]) && in MHD_run_from_select()
2278 (FD_ISSET (daemon->wpipe[0], (fd_set*)read_fd_set)) ) in MHD_run_from_select()
2279 (void) MHD_pipe_read_ (daemon->wpipe[0], &tmp, sizeof (tmp)); in MHD_run_from_select()
2281 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) in MHD_run_from_select()
2284 next = daemon->connections_head; in MHD_run_from_select()
2320 MHD_cleanup_connections (daemon); in MHD_run_from_select()
2334 MHD_select (struct MHD_Daemon *daemon, in MHD_select() argument
2348 if (MHD_YES == daemon->shutdown) in MHD_select()
2354 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) in MHD_select()
2356 if ( (MHD_USE_SUSPEND_RESUME == (daemon->options & MHD_USE_SUSPEND_RESUME)) && in MHD_select()
2357 (MHD_YES == resume_suspended_connections (daemon)) ) in MHD_select()
2361 if (MHD_NO == MHD_get_fdset2 (daemon, &rs, &ws, &es, &max, FD_SETSIZE)) in MHD_select()
2369 if ( (MHD_INVALID_SOCKET != daemon->socket_fd) && in MHD_select()
2370 (daemon->connections == daemon->connection_limit) && in MHD_select()
2371 (0 != (daemon->options & MHD_USE_PIPE_FOR_SHUTDOWN)) ) in MHD_select()
2372 FD_CLR (daemon->socket_fd, &rs); in MHD_select()
2377 if ( (MHD_INVALID_SOCKET != daemon->socket_fd) && in MHD_select()
2378 (MHD_YES != add_to_fd_set (daemon->socket_fd, in MHD_select()
2384 if ( (MHD_INVALID_PIPE_ != daemon->wpipe[0]) && in MHD_select()
2385 (MHD_YES != add_to_fd_set (daemon->wpipe[0], in MHD_select()
2398 else if ( (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && in MHD_select()
2399 (MHD_YES == MHD_get_timeout (daemon, &ltimeout)) ) in MHD_select()
2409 if (MHD_YES == daemon->shutdown) in MHD_select()
2416 MHD_DLOG (daemon, in MHD_select()
2422 return MHD_run_from_select (daemon, &rs, &ws, &es); in MHD_select()
2436 MHD_poll_all (struct MHD_Daemon *daemon, in MHD_poll_all() argument
2443 if ( (MHD_USE_SUSPEND_RESUME == (daemon->options & MHD_USE_SUSPEND_RESUME)) && in MHD_poll_all()
2444 (MHD_YES == resume_suspended_connections (daemon)) ) in MHD_poll_all()
2449 for (pos = daemon->connections_head; NULL != pos; pos = pos->next) in MHD_poll_all()
2465 MHD_DLOG(daemon, in MHD_poll_all()
2474 if ( (MHD_INVALID_SOCKET != daemon->socket_fd) && in MHD_poll_all()
2475 (daemon->connections < daemon->connection_limit) ) in MHD_poll_all()
2478 p[poll_server].fd = daemon->socket_fd; in MHD_poll_all()
2485 if (MHD_INVALID_PIPE_ != daemon->wpipe[0]) in MHD_poll_all()
2487 p[poll_server].fd = daemon->wpipe[0]; in MHD_poll_all()
2495 else if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) || in MHD_poll_all()
2496 (MHD_YES != MHD_get_timeout (daemon, &ltimeout)) ) in MHD_poll_all()
2502 for (pos = daemon->connections_head; NULL != pos; pos = pos->next) in MHD_poll_all()
2538 MHD_DLOG (daemon, in MHD_poll_all()
2546 if (MHD_YES == daemon->shutdown) in MHD_poll_all()
2552 next = daemon->connections_head; in MHD_poll_all()
2597 (void) MHD_accept_connection (daemon); in MHD_poll_all()
2602 (void) MHD_pipe_read_ (daemon->wpipe[0], &tmp, sizeof (tmp)); in MHD_poll_all()
2618 MHD_poll_listen_socket (struct MHD_Daemon *daemon, in MHD_poll_listen_socket() argument
2629 if (MHD_INVALID_SOCKET != daemon->socket_fd) in MHD_poll_listen_socket()
2631 p[poll_count].fd = daemon->socket_fd; in MHD_poll_listen_socket()
2637 if (MHD_INVALID_PIPE_ != daemon->wpipe[0]) in MHD_poll_listen_socket()
2639 p[poll_count].fd = daemon->wpipe[0]; in MHD_poll_listen_socket()
2655 MHD_DLOG (daemon, in MHD_poll_listen_socket()
2662 if (MHD_YES == daemon->shutdown) in MHD_poll_listen_socket()
2666 (void) MHD_accept_connection (daemon); in MHD_poll_listen_socket()
2680 MHD_poll (struct MHD_Daemon *daemon, in MHD_poll() argument
2684 if (MHD_YES == daemon->shutdown) in MHD_poll()
2686 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) in MHD_poll()
2687 return MHD_poll_all (daemon, may_block); in MHD_poll()
2689 return MHD_poll_listen_socket (daemon, may_block); in MHD_poll()
2718 MHD_epoll (struct MHD_Daemon *daemon, in MHD_epoll() argument
2732 if (-1 == daemon->epoll_fd) in MHD_epoll()
2734 if (MHD_YES == daemon->shutdown) in MHD_epoll()
2736 if ( (MHD_INVALID_SOCKET != daemon->socket_fd) && in MHD_epoll()
2737 (daemon->connections < daemon->connection_limit) && in MHD_epoll()
2738 (MHD_NO == daemon->listen_socket_in_epoll) ) in MHD_epoll()
2741 event.data.ptr = daemon; in MHD_epoll()
2742 if (0 != epoll_ctl (daemon->epoll_fd, in MHD_epoll()
2744 daemon->socket_fd, in MHD_epoll()
2748 MHD_DLOG (daemon, in MHD_epoll()
2754 daemon->listen_socket_in_epoll = MHD_YES; in MHD_epoll()
2756 if ( (MHD_YES == daemon->listen_socket_in_epoll) && in MHD_epoll()
2757 (daemon->connections == daemon->connection_limit) ) in MHD_epoll()
2761 if (0 != epoll_ctl (daemon->epoll_fd, in MHD_epoll()
2763 daemon->socket_fd, in MHD_epoll()
2766 daemon->listen_socket_in_epoll = MHD_NO; in MHD_epoll()
2770 if (MHD_YES == MHD_get_timeout (daemon, in MHD_epoll()
2792 num_events = epoll_wait (daemon->epoll_fd, in MHD_epoll()
2799 MHD_DLOG (daemon, in MHD_epoll()
2809 if ( (MHD_INVALID_PIPE_ != daemon->wpipe[0]) && in MHD_epoll()
2810 (daemon->wpipe[0] == events[i].data.fd) ) in MHD_epoll()
2812 (void) MHD_pipe_read_ (daemon->wpipe[0], &tmp, sizeof (tmp)); in MHD_epoll()
2815 if (daemon != events[i].data.ptr) in MHD_epoll()
2828 EDLL_insert (daemon->eready_head, in MHD_epoll()
2829 daemon->eready_tail, in MHD_epoll()
2840 EDLL_insert (daemon->eready_head, in MHD_epoll()
2841 daemon->eready_tail, in MHD_epoll()
2852 while ( (MHD_YES == MHD_accept_connection (daemon)) && in MHD_epoll()
2853 (daemon->connections < daemon->connection_limit) && in MHD_epoll()
2862 if ( (MHD_USE_SUSPEND_RESUME == (daemon->options & MHD_USE_SUSPEND_RESUME)) && in MHD_epoll()
2863 (MHD_YES == resume_suspended_connections (daemon)) ) in MHD_epoll()
2867 while (NULL != (pos = daemon->eready_tail)) in MHD_epoll()
2869 EDLL_remove (daemon->eready_head, in MHD_epoll()
2870 daemon->eready_tail, in MHD_epoll()
2888 next = daemon->manual_timeout_head; in MHD_epoll()
2898 next = daemon->normal_timeout_tail; in MHD_epoll()
2931 MHD_run (struct MHD_Daemon *daemon) in MHD_run() argument
2933 if ( (MHD_YES == daemon->shutdown) || in MHD_run()
2934 (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) || in MHD_run()
2935 (0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)) ) in MHD_run()
2937 if (0 != (daemon->options & MHD_USE_POLL)) in MHD_run()
2939 MHD_poll (daemon, MHD_NO); in MHD_run()
2940 MHD_cleanup_connections (daemon); in MHD_run()
2943 else if (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) in MHD_run()
2945 MHD_epoll (daemon, MHD_NO); in MHD_run()
2946 MHD_cleanup_connections (daemon); in MHD_run()
2951 MHD_select (daemon, MHD_NO); in MHD_run()
2968 struct MHD_Daemon *daemon = cls; in MHD_select_thread() local
2970 while (MHD_YES != daemon->shutdown) in MHD_select_thread()
2972 if (0 != (daemon->options & MHD_USE_POLL)) in MHD_select_thread()
2973 MHD_poll (daemon, MHD_YES); in MHD_select_thread()
2975 else if (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) in MHD_select_thread()
2976 MHD_epoll (daemon, MHD_YES); in MHD_select_thread()
2979 MHD_select (daemon, MHD_YES); in MHD_select_thread()
2980 MHD_cleanup_connections (daemon); in MHD_select_thread()
3029 struct MHD_Daemon *daemon; in MHD_start_daemon() local
3033 daemon = MHD_start_daemon_va (flags, port, apc, apc_cls, dh, dh_cls, ap); in MHD_start_daemon()
3035 return daemon; in MHD_start_daemon()
3059 MHD_quiesce_daemon (struct MHD_Daemon *daemon) in MHD_quiesce_daemon() argument
3064 ret = daemon->socket_fd; in MHD_quiesce_daemon()
3067 if ( (MHD_INVALID_PIPE_ == daemon->wpipe[1]) && in MHD_quiesce_daemon()
3068 (0 != (daemon->options & (MHD_USE_SELECT_INTERNALLY | MHD_USE_THREAD_PER_CONNECTION))) ) in MHD_quiesce_daemon()
3071 MHD_DLOG (daemon, in MHD_quiesce_daemon()
3077 if (NULL != daemon->worker_pool) in MHD_quiesce_daemon()
3078 for (i = 0; i < daemon->worker_pool_size; i++) in MHD_quiesce_daemon()
3080 daemon->worker_pool[i].socket_fd = MHD_INVALID_SOCKET; in MHD_quiesce_daemon()
3082 if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) && in MHD_quiesce_daemon()
3083 (-1 != daemon->worker_pool[i].epoll_fd) && in MHD_quiesce_daemon()
3084 (MHD_YES == daemon->worker_pool[i].listen_socket_in_epoll) ) in MHD_quiesce_daemon()
3086 if (0 != epoll_ctl (daemon->worker_pool[i].epoll_fd, in MHD_quiesce_daemon()
3091 daemon->worker_pool[i].listen_socket_in_epoll = MHD_NO; in MHD_quiesce_daemon()
3095 daemon->socket_fd = MHD_INVALID_SOCKET; in MHD_quiesce_daemon()
3097 if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) && in MHD_quiesce_daemon()
3098 (-1 != daemon->epoll_fd) && in MHD_quiesce_daemon()
3099 (MHD_YES == daemon->listen_socket_in_epoll) ) in MHD_quiesce_daemon()
3101 if (0 != epoll_ctl (daemon->epoll_fd, in MHD_quiesce_daemon()
3106 daemon->listen_socket_in_epoll = MHD_NO; in MHD_quiesce_daemon()
3134 parse_options_va (struct MHD_Daemon *daemon,
3148 parse_options (struct MHD_Daemon *daemon, in parse_options() argument
3156 ret = parse_options_va (daemon, servaddr, ap); in parse_options()
3171 parse_options_va (struct MHD_Daemon *daemon, in parse_options_va() argument
3188 daemon->pool_size = va_arg (ap, size_t); in parse_options_va()
3191 daemon->pool_increment= va_arg (ap, size_t); in parse_options_va()
3194 daemon->connection_limit = va_arg (ap, unsigned int); in parse_options_va()
3197 daemon->connection_timeout = va_arg (ap, unsigned int); in parse_options_va()
3200 daemon->notify_completed = in parse_options_va()
3202 daemon->notify_completed_cls = va_arg (ap, void *); in parse_options_va()
3205 daemon->notify_connection = in parse_options_va()
3207 daemon->notify_connection_cls = va_arg (ap, void *); in parse_options_va()
3210 daemon->per_ip_connection_limit = va_arg (ap, unsigned int); in parse_options_va()
3216 daemon->uri_log_callback = in parse_options_va()
3218 daemon->uri_log_callback_cls = va_arg (ap, void *); in parse_options_va()
3221 daemon->worker_pool_size = va_arg (ap, unsigned int); in parse_options_va()
3222 if (daemon->worker_pool_size >= (SIZE_MAX / sizeof (struct MHD_Daemon))) in parse_options_va()
3225 MHD_DLOG (daemon, in parse_options_va()
3227 daemon->worker_pool_size); in parse_options_va()
3234 if (0 != (daemon->options & MHD_USE_SSL)) in parse_options_va()
3236 daemon->https_mem_key = va_arg (ap, const char *); in parse_options_va()
3241 MHD_DLOG (daemon, in parse_options_va()
3248 if (0 != (daemon->options & MHD_USE_SSL)) in parse_options_va()
3250 daemon->https_key_password = va_arg (ap, const char *); in parse_options_va()
3255 MHD_DLOG (daemon, in parse_options_va()
3262 if (0 != (daemon->options & MHD_USE_SSL)) in parse_options_va()
3264 daemon->https_mem_cert = va_arg (ap, const char *); in parse_options_va()
3269 MHD_DLOG (daemon, in parse_options_va()
3276 if (0 != (daemon->options & MHD_USE_SSL)) in parse_options_va()
3278 daemon->https_mem_trust = va_arg (ap, const char *); in parse_options_va()
3283 MHD_DLOG (daemon, in parse_options_va()
3292 if (0 != (daemon->options & MHD_USE_SSL)) in parse_options_va()
3294 daemon->https_mem_dhparams = va_arg (ap, const char *); in parse_options_va()
3299 MHD_DLOG (daemon, in parse_options_va()
3306 if (0 != (daemon->options & MHD_USE_SSL)) in parse_options_va()
3308 daemon->https_mem_cipher = va_arg (ap, const char *); in parse_options_va()
3313 MHD_DLOG (daemon, in parse_options_va()
3324 daemon->digest_auth_rand_size = va_arg (ap, size_t); in parse_options_va()
3325 daemon->digest_auth_random = va_arg (ap, const char *); in parse_options_va()
3328 daemon->nonce_nc_size = va_arg (ap, unsigned int); in parse_options_va()
3332 daemon->socket_fd = va_arg (ap, MHD_socket); in parse_options_va()
3336 daemon->custom_error_log = in parse_options_va()
3338 daemon->custom_error_log_cls = va_arg (ap, void *); in parse_options_va()
3345 daemon->thread_stack_size = va_arg (ap, size_t); in parse_options_va()
3349 daemon->fastopen_queue_size = va_arg (ap, unsigned int); in parse_options_va()
3353 daemon->listening_address_reuse = va_arg (ap, unsigned int) ? 1 : -1; in parse_options_va()
3366 if (MHD_YES != parse_options (daemon, in parse_options_va()
3381 if (MHD_YES != parse_options (daemon, in parse_options_va()
3390 if (MHD_YES != parse_options (daemon, in parse_options_va()
3399 if (MHD_YES != parse_options (daemon, in parse_options_va()
3416 if (MHD_YES != parse_options (daemon, in parse_options_va()
3429 if (MHD_YES != parse_options (daemon, in parse_options_va()
3439 if (MHD_YES != parse_options (daemon, in parse_options_va()
3454 daemon->unescape_callback = in parse_options_va()
3456 daemon->unescape_callback_cls = va_arg (ap, void *); in parse_options_va()
3463 MHD_DLOG (daemon, in parse_options_va()
3469 MHD_DLOG (daemon, in parse_options_va()
3490 create_socket (struct MHD_Daemon *daemon, in create_socket() argument
3507 make_nonblocking_noninheritable (daemon, fd); in create_socket()
3521 setup_epoll_to_listen (struct MHD_Daemon *daemon) in setup_epoll_to_listen() argument
3526 daemon->epoll_fd = epoll_create1 (EPOLL_CLOEXEC); in setup_epoll_to_listen()
3528 daemon->epoll_fd = epoll_create (MAX_EVENTS); in setup_epoll_to_listen()
3530 if (-1 == daemon->epoll_fd) in setup_epoll_to_listen()
3533 MHD_DLOG (daemon, in setup_epoll_to_listen()
3542 int fdflags = fcntl (daemon->epoll_fd, F_GETFD); in setup_epoll_to_listen()
3543 if (0 > fdflags || 0 > fcntl (daemon->epoll_fd, F_SETFD, fdflags | FD_CLOEXEC)) in setup_epoll_to_listen()
3546 MHD_DLOG (daemon, in setup_epoll_to_listen()
3554 make_nonblocking_noninheritable (daemon, in setup_epoll_to_listen()
3555 daemon->epoll_fd); in setup_epoll_to_listen()
3556 if (MHD_INVALID_SOCKET == daemon->socket_fd) in setup_epoll_to_listen()
3559 event.data.ptr = daemon; in setup_epoll_to_listen()
3560 if (0 != epoll_ctl (daemon->epoll_fd, in setup_epoll_to_listen()
3562 daemon->socket_fd, in setup_epoll_to_listen()
3566 MHD_DLOG (daemon, in setup_epoll_to_listen()
3572 if ( (MHD_INVALID_PIPE_ != daemon->wpipe[0]) && in setup_epoll_to_listen()
3573 (MHD_USE_SUSPEND_RESUME == (daemon->options & MHD_USE_SUSPEND_RESUME)) ) in setup_epoll_to_listen()
3577 event.data.fd = daemon->wpipe[0]; in setup_epoll_to_listen()
3578 if (0 != epoll_ctl (daemon->epoll_fd, in setup_epoll_to_listen()
3580 daemon->wpipe[0], in setup_epoll_to_listen()
3584 MHD_DLOG (daemon, in setup_epoll_to_listen()
3591 daemon->listen_socket_in_epoll = MHD_YES; in setup_epoll_to_listen()
3623 struct MHD_Daemon *daemon; in MHD_start_daemon_va() local
3653 if (NULL == (daemon = malloc (sizeof (struct MHD_Daemon)))) in MHD_start_daemon_va()
3655 memset (daemon, 0, sizeof (struct MHD_Daemon)); in MHD_start_daemon_va()
3657 daemon->epoll_fd = -1; in MHD_start_daemon_va()
3660 daemon->socket_fd = MHD_INVALID_SOCKET; in MHD_start_daemon_va()
3661 daemon->listening_address_reuse = 0; in MHD_start_daemon_va()
3662 daemon->options = flags; in MHD_start_daemon_va()
3666 daemon->options |= MHD_USE_EPOLL_TURBO; in MHD_start_daemon_va()
3668 daemon->port = port; in MHD_start_daemon_va()
3669 daemon->apc = apc; in MHD_start_daemon_va()
3670 daemon->apc_cls = apc_cls; in MHD_start_daemon_va()
3671 daemon->default_handler = dh; in MHD_start_daemon_va()
3672 daemon->default_handler_cls = dh_cls; in MHD_start_daemon_va()
3673 daemon->connections = 0; in MHD_start_daemon_va()
3674 daemon->connection_limit = MHD_MAX_CONNECTIONS_DEFAULT; in MHD_start_daemon_va()
3675 daemon->pool_size = MHD_POOL_SIZE_DEFAULT; in MHD_start_daemon_va()
3676 daemon->pool_increment = MHD_BUF_INC_SIZE; in MHD_start_daemon_va()
3677 daemon->unescape_callback = &unescape_wrapper; in MHD_start_daemon_va()
3678 daemon->connection_timeout = 0; /* no timeout */ in MHD_start_daemon_va()
3679 daemon->wpipe[0] = MHD_INVALID_PIPE_; in MHD_start_daemon_va()
3680 daemon->wpipe[1] = MHD_INVALID_PIPE_; in MHD_start_daemon_va()
3682 daemon->custom_error_log = (MHD_LogCallback) &vfprintf; in MHD_start_daemon_va()
3683 daemon->custom_error_log_cls = stderr; in MHD_start_daemon_va()
3686 use_pipe = (0 != (daemon->options & (MHD_USE_NO_LISTEN_SOCKET | MHD_USE_PIPE_FOR_SHUTDOWN))); in MHD_start_daemon_va()
3692 if ( (use_pipe) && (0 != MHD_pipe_ (daemon->wpipe)) ) in MHD_start_daemon_va()
3695 MHD_DLOG (daemon, in MHD_start_daemon_va()
3699 free (daemon); in MHD_start_daemon_va()
3705 (daemon->wpipe[0] >= FD_SETSIZE) ) in MHD_start_daemon_va()
3708 MHD_DLOG (daemon, in MHD_start_daemon_va()
3711 if (0 != MHD_pipe_close_ (daemon->wpipe[0])) in MHD_start_daemon_va()
3713 if (0 != MHD_pipe_close_ (daemon->wpipe[1])) in MHD_start_daemon_va()
3715 free (daemon); in MHD_start_daemon_va()
3720 daemon->digest_auth_rand_size = 0; in MHD_start_daemon_va()
3721 daemon->digest_auth_random = NULL; in MHD_start_daemon_va()
3722 daemon->nonce_nc_size = 4; /* tiny */ in MHD_start_daemon_va()
3726 if (MHD_YES != parse_options_va (daemon, &servaddr, ap)) in MHD_start_daemon_va()
3728 free (daemon); in MHD_start_daemon_va()
3732 if (daemon->nonce_nc_size > 0) in MHD_start_daemon_va()
3734 if ( ( (size_t) (daemon->nonce_nc_size * sizeof (struct MHD_NonceNc))) / in MHD_start_daemon_va()
3735 sizeof(struct MHD_NonceNc) != daemon->nonce_nc_size) in MHD_start_daemon_va()
3738 MHD_DLOG (daemon, in MHD_start_daemon_va()
3741 free (daemon); in MHD_start_daemon_va()
3744 daemon->nnc = malloc (daemon->nonce_nc_size * sizeof (struct MHD_NonceNc)); in MHD_start_daemon_va()
3745 if (NULL == daemon->nnc) in MHD_start_daemon_va()
3748 MHD_DLOG (daemon, in MHD_start_daemon_va()
3752 free (daemon); in MHD_start_daemon_va()
3757 if (MHD_YES != MHD_mutex_create_ (&daemon->nnc_lock)) in MHD_start_daemon_va()
3760 MHD_DLOG (daemon, in MHD_start_daemon_va()
3763 free (daemon->nnc); in MHD_start_daemon_va()
3764 free (daemon); in MHD_start_daemon_va()
3771 (daemon->worker_pool_size > 0) ) in MHD_start_daemon_va()
3774 MHD_DLOG (daemon, in MHD_start_daemon_va()
3784 MHD_DLOG (daemon, in MHD_start_daemon_va()
3794 MHD_DLOG (daemon, in MHD_start_daemon_va()
3800 if ( (MHD_INVALID_SOCKET == daemon->socket_fd) && in MHD_start_daemon_va()
3801 (0 == (daemon->options & MHD_USE_NO_LISTEN_SOCKET)) ) in MHD_start_daemon_va()
3805 socket_fd = create_socket (daemon, in MHD_start_daemon_va()
3808 socket_fd = create_socket (daemon, in MHD_start_daemon_va()
3813 MHD_DLOG (daemon, in MHD_start_daemon_va()
3821 if (0 == daemon->listening_address_reuse) in MHD_start_daemon_va()
3831 MHD_DLOG (daemon, in MHD_start_daemon_va()
3837 else if (daemon->listening_address_reuse > 0) in MHD_start_daemon_va()
3852 MHD_DLOG (daemon, in MHD_start_daemon_va()
3874 MHD_DLOG (daemon, in MHD_start_daemon_va()
3884 MHD_DLOG (daemon, in MHD_start_daemon_va()
3905 MHD_DLOG (daemon, in MHD_start_daemon_va()
3913 MHD_DLOG (daemon, in MHD_start_daemon_va()
3953 daemon->socket_fd = socket_fd; in MHD_start_daemon_va()
3974 MHD_DLOG (daemon, in MHD_start_daemon_va()
3985 MHD_DLOG (daemon, in MHD_start_daemon_va()
3997 if (0 == daemon->fastopen_queue_size) in MHD_start_daemon_va()
3998 daemon->fastopen_queue_size = MHD_TCP_FASTOPEN_QUEUE_SIZE_DEFAULT; in MHD_start_daemon_va()
4001 &daemon->fastopen_queue_size, in MHD_start_daemon_va()
4002 sizeof (daemon->fastopen_queue_size))) in MHD_start_daemon_va()
4005 MHD_DLOG (daemon, in MHD_start_daemon_va()
4019 MHD_DLOG (daemon, in MHD_start_daemon_va()
4032 MHD_DLOG (daemon, in MHD_start_daemon_va()
4043 socket_fd = daemon->socket_fd; in MHD_start_daemon_va()
4050 MHD_DLOG (daemon, in MHD_start_daemon_va()
4063 (0 == daemon->worker_pool_size) && in MHD_start_daemon_va()
4064 (0 == (daemon->options & MHD_USE_NO_LISTEN_SOCKET)) ) in MHD_start_daemon_va()
4069 MHD_DLOG (daemon, in MHD_start_daemon_va()
4074 if (MHD_YES != setup_epoll_to_listen (daemon)) in MHD_start_daemon_va()
4081 MHD_DLOG (daemon, in MHD_start_daemon_va()
4088 if (MHD_YES != MHD_mutex_create_ (&daemon->per_ip_connection_mutex)) in MHD_start_daemon_va()
4091 MHD_DLOG (daemon, in MHD_start_daemon_va()
4099 if (MHD_YES != MHD_mutex_create_ (&daemon->cleanup_connection_mutex)) in MHD_start_daemon_va()
4102 MHD_DLOG (daemon, in MHD_start_daemon_va()
4105 (void) MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); in MHD_start_daemon_va()
4114 if ((0 != (flags & MHD_USE_SSL)) && (0 != MHD_TLS_init (daemon))) in MHD_start_daemon_va()
4117 MHD_DLOG (daemon, in MHD_start_daemon_va()
4123 (void) MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); in MHD_start_daemon_va()
4124 (void) MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex); in MHD_start_daemon_va()
4130 (0 == daemon->worker_pool_size)) ) && in MHD_start_daemon_va()
4131 (0 == (daemon->options & MHD_USE_NO_LISTEN_SOCKET)) && in MHD_start_daemon_va()
4133 create_thread (&daemon->pid, daemon, &MHD_select_thread, daemon)))) in MHD_start_daemon_va()
4136 MHD_DLOG (daemon, in MHD_start_daemon_va()
4140 (void) MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); in MHD_start_daemon_va()
4141 (void) MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex); in MHD_start_daemon_va()
4147 if ( (daemon->worker_pool_size > 0) && in MHD_start_daemon_va()
4148 (0 == (daemon->options & MHD_USE_NO_LISTEN_SOCKET)) ) in MHD_start_daemon_va()
4159 unsigned int conns_per_thread = daemon->connection_limit in MHD_start_daemon_va()
4160 / daemon->worker_pool_size; in MHD_start_daemon_va()
4161 unsigned int leftover_conns = daemon->connection_limit in MHD_start_daemon_va()
4162 % daemon->worker_pool_size; in MHD_start_daemon_va()
4182 daemon->worker_pool = malloc (sizeof (struct MHD_Daemon) in MHD_start_daemon_va()
4183 * daemon->worker_pool_size); in MHD_start_daemon_va()
4184 if (NULL == daemon->worker_pool) in MHD_start_daemon_va()
4188 for (i = 0; i < daemon->worker_pool_size; ++i) in MHD_start_daemon_va()
4191 struct MHD_Daemon *d = &daemon->worker_pool[i]; in MHD_start_daemon_va()
4193 memcpy (d, daemon, sizeof (struct MHD_Daemon)); in MHD_start_daemon_va()
4197 d->master = daemon; in MHD_start_daemon_va()
4205 MHD_DLOG (daemon, in MHD_start_daemon_va()
4217 MHD_DLOG (daemon, in MHD_start_daemon_va()
4235 if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) && in MHD_start_daemon_va()
4243 MHD_DLOG (daemon, in MHD_start_daemon_va()
4251 create_thread (&d->pid, daemon, &MHD_select_thread, d))) in MHD_start_daemon_va()
4254 MHD_DLOG (daemon, in MHD_start_daemon_va()
4268 daemon->https_key_password = NULL; in MHD_start_daemon_va()
4271 return daemon; in MHD_start_daemon_va()
4283 (void) MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); in MHD_start_daemon_va()
4284 (void) MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex); in MHD_start_daemon_va()
4285 if (NULL != daemon->worker_pool) in MHD_start_daemon_va()
4286 free (daemon->worker_pool); in MHD_start_daemon_va()
4294 daemon->worker_pool_size = i; in MHD_start_daemon_va()
4295 MHD_stop_daemon (daemon); in MHD_start_daemon_va()
4302 if (-1 != daemon->epoll_fd) in MHD_start_daemon_va()
4303 close (daemon->epoll_fd); in MHD_start_daemon_va()
4306 free (daemon->nnc); in MHD_start_daemon_va()
4307 (void) MHD_mutex_destroy_ (&daemon->nnc_lock); in MHD_start_daemon_va()
4309 free (daemon); in MHD_start_daemon_va()
4323 struct MHD_Daemon *daemon = pos->daemon; in close_connection() local
4327 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) in close_connection()
4329 if (pos->connection_timeout == pos->daemon->connection_timeout) in close_connection()
4330 XDLL_remove (daemon->normal_timeout_head, in close_connection()
4331 daemon->normal_timeout_tail, in close_connection()
4334 XDLL_remove (daemon->manual_timeout_head, in close_connection()
4335 daemon->manual_timeout_tail, in close_connection()
4337 DLL_remove (daemon->connections_head, in close_connection()
4338 daemon->connections_tail, in close_connection()
4341 DLL_insert (daemon->cleanup_head, in close_connection()
4342 daemon->cleanup_tail, in close_connection()
4355 close_all_connections (struct MHD_Daemon *daemon) in close_all_connections() argument
4361 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && in close_all_connections()
4362 (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) ) in close_all_connections()
4364 for (pos = daemon->connections_head; NULL != pos; pos = pos->next) in close_all_connections()
4369 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && in close_all_connections()
4370 (MHD_INVALID_PIPE_ != daemon->wpipe[1]) && in close_all_connections()
4371 (1 != MHD_pipe_write_ (daemon->wpipe[1], "e", 1)) ) in close_all_connections()
4375 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && in close_all_connections()
4376 (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) ) in close_all_connections()
4380 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) in close_all_connections()
4382 for (pos = daemon->connections_head; NULL != pos; pos = pos->next) in close_all_connections()
4391 while (NULL != (pos = daemon->connections_head)) in close_all_connections()
4393 MHD_cleanup_connections (daemon); in close_all_connections()
4404 epoll_shutdown (struct MHD_Daemon *daemon) in epoll_shutdown() argument
4408 if (MHD_INVALID_PIPE_ == daemon->wpipe[1]) in epoll_shutdown()
4415 if (0 != epoll_ctl (daemon->epoll_fd, in epoll_shutdown()
4417 daemon->wpipe[1], in epoll_shutdown()
4431 MHD_stop_daemon (struct MHD_Daemon *daemon) in MHD_stop_daemon() argument
4436 if (NULL == daemon) in MHD_stop_daemon()
4438 daemon->shutdown = MHD_YES; in MHD_stop_daemon()
4439 fd = daemon->socket_fd; in MHD_stop_daemon()
4440 daemon->socket_fd = MHD_INVALID_SOCKET; in MHD_stop_daemon()
4442 if (NULL != daemon->worker_pool) in MHD_stop_daemon()
4445 for (i = 0; i < daemon->worker_pool_size; ++i) in MHD_stop_daemon()
4447 daemon->worker_pool[i].shutdown = MHD_YES; in MHD_stop_daemon()
4448 daemon->worker_pool[i].socket_fd = MHD_INVALID_SOCKET; in MHD_stop_daemon()
4450 if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) && in MHD_stop_daemon()
4451 (-1 != daemon->worker_pool[i].epoll_fd) && in MHD_stop_daemon()
4453 epoll_shutdown (&daemon->worker_pool[i]); in MHD_stop_daemon()
4457 if (MHD_INVALID_PIPE_ != daemon->wpipe[1]) in MHD_stop_daemon()
4459 if (1 != MHD_pipe_write_ (daemon->wpipe[1], "e", 1)) in MHD_stop_daemon()
4471 if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) && in MHD_stop_daemon()
4472 (-1 != daemon->epoll_fd) && in MHD_stop_daemon()
4474 epoll_shutdown (daemon); in MHD_stop_daemon()
4479 MHD_DLOG (daemon, in MHD_stop_daemon()
4486 if (NULL != daemon->worker_pool) in MHD_stop_daemon()
4489 for (i = 0; i < daemon->worker_pool_size; ++i) in MHD_stop_daemon()
4491 if (MHD_INVALID_PIPE_ != daemon->worker_pool[i].wpipe[1]) in MHD_stop_daemon()
4493 if (1 != MHD_pipe_write_ (daemon->worker_pool[i].wpipe[1], "e", 1)) in MHD_stop_daemon()
4496 if (0 != MHD_join_thread_ (daemon->worker_pool[i].pid)) in MHD_stop_daemon()
4498 close_all_connections (&daemon->worker_pool[i]); in MHD_stop_daemon()
4499 (void) MHD_mutex_destroy_ (&daemon->worker_pool[i].cleanup_connection_mutex); in MHD_stop_daemon()
4501 if ( (-1 != daemon->worker_pool[i].epoll_fd) && in MHD_stop_daemon()
4502 (0 != MHD_socket_close_ (daemon->worker_pool[i].epoll_fd)) ) in MHD_stop_daemon()
4505 if ( (MHD_USE_SUSPEND_RESUME == (daemon->options & MHD_USE_SUSPEND_RESUME)) ) in MHD_stop_daemon()
4507 if (MHD_INVALID_PIPE_ != daemon->worker_pool[i].wpipe[1]) in MHD_stop_daemon()
4509 if (0 != MHD_pipe_close_ (daemon->worker_pool[i].wpipe[0])) in MHD_stop_daemon()
4511 if (0 != MHD_pipe_close_ (daemon->worker_pool[i].wpipe[1])) in MHD_stop_daemon()
4516 free (daemon->worker_pool); in MHD_stop_daemon()
4521 if ((0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) || in MHD_stop_daemon()
4522 ((0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)) in MHD_stop_daemon()
4523 && (0 == daemon->worker_pool_size))) in MHD_stop_daemon()
4525 if (0 != MHD_join_thread_ (daemon->pid)) in MHD_stop_daemon()
4531 close_all_connections (daemon); in MHD_stop_daemon()
4538 if (0 != (daemon->options & MHD_USE_SSL)) in MHD_stop_daemon()
4540 MHD_TLS_deinit (daemon); in MHD_stop_daemon()
4544 if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) && in MHD_stop_daemon()
4545 (-1 != daemon->epoll_fd) && in MHD_stop_daemon()
4546 (0 != MHD_socket_close_ (daemon->epoll_fd)) ) in MHD_stop_daemon()
4551 free (daemon->nnc); in MHD_stop_daemon()
4552 (void) MHD_mutex_destroy_ (&daemon->nnc_lock); in MHD_stop_daemon()
4554 (void) MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex); in MHD_stop_daemon()
4555 (void) MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); in MHD_stop_daemon()
4557 if (MHD_INVALID_PIPE_ != daemon->wpipe[1]) in MHD_stop_daemon()
4559 if (0 != MHD_pipe_close_ (daemon->wpipe[0])) in MHD_stop_daemon()
4561 if (0 != MHD_pipe_close_ (daemon->wpipe[1])) in MHD_stop_daemon()
4564 free (daemon); in MHD_stop_daemon()
4580 MHD_get_daemon_info (struct MHD_Daemon *daemon, in MHD_get_daemon_info() argument
4591 return (const union MHD_DaemonInfo *) &daemon->socket_fd; in MHD_get_daemon_info()
4594 return (const union MHD_DaemonInfo *) &daemon->epoll_fd; in MHD_get_daemon_info()
4597 MHD_cleanup_connections (daemon); in MHD_get_daemon_info()
4598 if (daemon->worker_pool) in MHD_get_daemon_info()
4603 daemon->connections = 0; in MHD_get_daemon_info()
4604 for (i=0;i<daemon->worker_pool_size;i++) in MHD_get_daemon_info()
4606 MHD_cleanup_connections (&daemon->worker_pool[i]); in MHD_get_daemon_info()
4607 daemon->connections += daemon->worker_pool[i].connections; in MHD_get_daemon_info()
4610 return (const union MHD_DaemonInfo *) &daemon->connections; in MHD_get_daemon_info()