aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/daemon.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/daemon.c')
-rw-r--r--src/microhttpd/daemon.c79
1 files changed, 46 insertions, 33 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index ea958204..2c5d220d 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -842,7 +842,6 @@ MHD_handle_connection (void *data)
842 MHD_socket maxsock; 842 MHD_socket maxsock;
843 struct timeval tv; 843 struct timeval tv;
844 struct timeval *tvp; 844 struct timeval *tvp;
845 unsigned int timeout;
846 time_t now; 845 time_t now;
847#if WINDOWS 846#if WINDOWS
848 MHD_pipe spipe = con->daemon->wpipe[0]; 847 MHD_pipe spipe = con->daemon->wpipe[0];
@@ -857,10 +856,10 @@ MHD_handle_connection (void *data)
857 struct pollfd p[1 + EXTRA_SLOTS]; 856 struct pollfd p[1 + EXTRA_SLOTS];
858#endif 857#endif
859 858
860 timeout = con->daemon->connection_timeout;
861 while ( (MHD_YES != con->daemon->shutdown) && 859 while ( (MHD_YES != con->daemon->shutdown) &&
862 (MHD_CONNECTION_CLOSED != con->state) ) 860 (MHD_CONNECTION_CLOSED != con->state) )
863 { 861 {
862 unsigned const int timeout = con->daemon->connection_timeout;
864 tvp = NULL; 863 tvp = NULL;
865#if HTTPS_SUPPORT 864#if HTTPS_SUPPORT
866 if (MHD_YES == con->tls_read_ready) 865 if (MHD_YES == con->tls_read_ready)
@@ -1563,12 +1562,15 @@ internal_add_connection (struct MHD_Daemon *daemon,
1563 } 1562 }
1564#endif 1563#endif
1565 1564
1566 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1565 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
1567 (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) ) 1566 {
1568 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 1567 if (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex))
1569 XDLL_insert (daemon->normal_timeout_head, 1568 MHD_PANIC ("Failed to acquire cleanup mutex\n");
1570 daemon->normal_timeout_tail, 1569 }
1571 connection); 1570 else
1571 XDLL_insert (daemon->normal_timeout_head,
1572 daemon->normal_timeout_tail,
1573 connection);
1572 DLL_insert (daemon->connections_head, 1574 DLL_insert (daemon->connections_head,
1573 daemon->connections_tail, 1575 daemon->connections_tail,
1574 connection); 1576 connection);
@@ -1655,15 +1657,18 @@ internal_add_connection (struct MHD_Daemon *daemon,
1655 if (0 != MHD_socket_close_ (client_socket)) 1657 if (0 != MHD_socket_close_ (client_socket))
1656 MHD_PANIC ("close failed\n"); 1658 MHD_PANIC ("close failed\n");
1657 MHD_ip_limit_del (daemon, addr, addrlen); 1659 MHD_ip_limit_del (daemon, addr, addrlen);
1658 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1660 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
1659 (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) ) 1661 {
1660 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 1662 if (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex))
1663 MHD_PANIC ("Failed to acquire cleanup mutex\n");
1664 }
1665 else
1666 XDLL_remove (daemon->normal_timeout_head,
1667 daemon->normal_timeout_tail,
1668 connection);
1661 DLL_remove (daemon->connections_head, 1669 DLL_remove (daemon->connections_head,
1662 daemon->connections_tail, 1670 daemon->connections_tail,
1663 connection); 1671 connection);
1664 XDLL_remove (daemon->normal_timeout_head,
1665 daemon->normal_timeout_tail,
1666 connection);
1667 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1672 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1668 (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) ) 1673 (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
1669 MHD_PANIC ("Failed to release cleanup mutex\n"); 1674 MHD_PANIC ("Failed to release cleanup mutex\n");
@@ -1712,23 +1717,28 @@ MHD_suspend_connection (struct MHD_Connection *connection)
1712 daemon = connection->daemon; 1717 daemon = connection->daemon;
1713 if (MHD_USE_SUSPEND_RESUME != (daemon->options & MHD_USE_SUSPEND_RESUME)) 1718 if (MHD_USE_SUSPEND_RESUME != (daemon->options & MHD_USE_SUSPEND_RESUME))
1714 MHD_PANIC ("Cannot suspend connections without enabling MHD_USE_SUSPEND_RESUME!\n"); 1719 MHD_PANIC ("Cannot suspend connections without enabling MHD_USE_SUSPEND_RESUME!\n");
1715 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1720 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
1716 (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) ) 1721 {
1717 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 1722 if (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex))
1723 MHD_PANIC ("Failed to acquire cleanup mutex\n");
1724 }
1725 else
1726 {
1727 if (connection->connection_timeout == daemon->connection_timeout)
1728 XDLL_remove (daemon->normal_timeout_head,
1729 daemon->normal_timeout_tail,
1730 connection);
1731 else
1732 XDLL_remove (daemon->manual_timeout_head,
1733 daemon->manual_timeout_tail,
1734 connection);
1735 }
1718 DLL_remove (daemon->connections_head, 1736 DLL_remove (daemon->connections_head,
1719 daemon->connections_tail, 1737 daemon->connections_tail,
1720 connection); 1738 connection);
1721 DLL_insert (daemon->suspended_connections_head, 1739 DLL_insert (daemon->suspended_connections_head,
1722 daemon->suspended_connections_tail, 1740 daemon->suspended_connections_tail,
1723 connection); 1741 connection);
1724 if (connection->connection_timeout == daemon->connection_timeout)
1725 XDLL_remove (daemon->normal_timeout_head,
1726 daemon->normal_timeout_tail,
1727 connection);
1728 else
1729 XDLL_remove (daemon->manual_timeout_head,
1730 daemon->manual_timeout_tail,
1731 connection);
1732#if EPOLL_SUPPORT 1742#if EPOLL_SUPPORT
1733 if (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) 1743 if (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY))
1734 { 1744 {
@@ -1826,14 +1836,17 @@ resume_suspended_connections (struct MHD_Daemon *daemon)
1826 DLL_insert (daemon->connections_head, 1836 DLL_insert (daemon->connections_head,
1827 daemon->connections_tail, 1837 daemon->connections_tail,
1828 pos); 1838 pos);
1829 if (pos->connection_timeout == daemon->connection_timeout) 1839 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
1830 XDLL_insert (daemon->normal_timeout_head, 1840 {
1831 daemon->normal_timeout_tail, 1841 if (pos->connection_timeout == daemon->connection_timeout)
1832 pos); 1842 XDLL_insert (daemon->normal_timeout_head,
1833 else 1843 daemon->normal_timeout_tail,
1834 XDLL_insert (daemon->manual_timeout_head, 1844 pos);
1835 daemon->manual_timeout_tail, 1845 else
1836 pos); 1846 XDLL_insert (daemon->manual_timeout_head,
1847 daemon->manual_timeout_tail,
1848 pos);
1849 }
1837#if EPOLL_SUPPORT 1850#if EPOLL_SUPPORT
1838 if (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) 1851 if (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY))
1839 { 1852 {