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.c49
1 files changed, 25 insertions, 24 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 4845d60a..7e13e311 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -33,6 +33,7 @@
33#include "mhd_limits.h" 33#include "mhd_limits.h"
34#include "autoinit_funcs.h" 34#include "autoinit_funcs.h"
35#include "mhd_mono_clock.h" 35#include "mhd_mono_clock.h"
36#include "mhd_locks.h"
36 37
37#if HAVE_SEARCH_H 38#if HAVE_SEARCH_H
38#include <search.h> 39#include <search.h>
@@ -267,7 +268,7 @@ struct MHD_IPCount
267static void 268static void
268MHD_ip_count_lock (struct MHD_Daemon *daemon) 269MHD_ip_count_lock (struct MHD_Daemon *daemon)
269{ 270{
270 if (MHD_YES != MHD_mutex_lock_(&daemon->per_ip_connection_mutex)) 271 if (!MHD_mutex_lock_(&daemon->per_ip_connection_mutex))
271 { 272 {
272 MHD_PANIC ("Failed to acquire IP connection limit mutex\n"); 273 MHD_PANIC ("Failed to acquire IP connection limit mutex\n");
273 } 274 }
@@ -282,7 +283,7 @@ MHD_ip_count_lock (struct MHD_Daemon *daemon)
282static void 283static void
283MHD_ip_count_unlock (struct MHD_Daemon *daemon) 284MHD_ip_count_unlock (struct MHD_Daemon *daemon)
284{ 285{
285 if (MHD_YES != MHD_mutex_unlock_(&daemon->per_ip_connection_mutex)) 286 if (!MHD_mutex_unlock_(&daemon->per_ip_connection_mutex))
286 { 287 {
287 MHD_PANIC ("Failed to release IP connection limit mutex\n"); 288 MHD_PANIC ("Failed to release IP connection limit mutex\n");
288 } 289 }
@@ -1536,7 +1537,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
1536 1537
1537 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 1538 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
1538 { 1539 {
1539 if (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) 1540 if (!MHD_mutex_lock_ (&daemon->cleanup_connection_mutex))
1540 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 1541 MHD_PANIC ("Failed to acquire cleanup mutex\n");
1541 } 1542 }
1542 else 1543 else
@@ -1547,7 +1548,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
1547 daemon->connections_tail, 1548 daemon->connections_tail,
1548 connection); 1549 connection);
1549 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1550 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1550 (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) ) 1551 (!MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
1551 MHD_PANIC ("Failed to release cleanup mutex\n"); 1552 MHD_PANIC ("Failed to release cleanup mutex\n");
1552 1553
1553 if (NULL != daemon->notify_connection) 1554 if (NULL != daemon->notify_connection)
@@ -1631,7 +1632,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
1631 MHD_ip_limit_del (daemon, addr, addrlen); 1632 MHD_ip_limit_del (daemon, addr, addrlen);
1632 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 1633 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
1633 { 1634 {
1634 if (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) 1635 if (!MHD_mutex_lock_ (&daemon->cleanup_connection_mutex))
1635 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 1636 MHD_PANIC ("Failed to acquire cleanup mutex\n");
1636 } 1637 }
1637 else 1638 else
@@ -1642,7 +1643,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
1642 daemon->connections_tail, 1643 daemon->connections_tail,
1643 connection); 1644 connection);
1644 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1645 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1645 (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) ) 1646 (!MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
1646 MHD_PANIC ("Failed to release cleanup mutex\n"); 1647 MHD_PANIC ("Failed to release cleanup mutex\n");
1647 MHD_pool_destroy (connection->pool); 1648 MHD_pool_destroy (connection->pool);
1648 free (connection->addr); 1649 free (connection->addr);
@@ -1689,7 +1690,7 @@ MHD_suspend_connection (struct MHD_Connection *connection)
1689 MHD_PANIC ("Cannot suspend connections without enabling MHD_USE_SUSPEND_RESUME!\n"); 1690 MHD_PANIC ("Cannot suspend connections without enabling MHD_USE_SUSPEND_RESUME!\n");
1690 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 1691 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
1691 { 1692 {
1692 if (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) 1693 if (!MHD_mutex_lock_ (&daemon->cleanup_connection_mutex))
1693 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 1694 MHD_PANIC ("Failed to acquire cleanup mutex\n");
1694 } 1695 }
1695 else 1696 else
@@ -1733,7 +1734,7 @@ MHD_suspend_connection (struct MHD_Connection *connection)
1733#endif 1734#endif
1734 connection->suspended = MHD_YES; 1735 connection->suspended = MHD_YES;
1735 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1736 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1736 (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) ) 1737 (!MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
1737 MHD_PANIC ("Failed to release cleanup mutex\n"); 1738 MHD_PANIC ("Failed to release cleanup mutex\n");
1738} 1739}
1739 1740
@@ -1755,7 +1756,7 @@ MHD_resume_connection (struct MHD_Connection *connection)
1755 if (MHD_USE_SUSPEND_RESUME != (daemon->options & MHD_USE_SUSPEND_RESUME)) 1756 if (MHD_USE_SUSPEND_RESUME != (daemon->options & MHD_USE_SUSPEND_RESUME))
1756 MHD_PANIC ("Cannot resume connections without enabling MHD_USE_SUSPEND_RESUME!\n"); 1757 MHD_PANIC ("Cannot resume connections without enabling MHD_USE_SUSPEND_RESUME!\n");
1757 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1758 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1758 (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) ) 1759 (!MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) )
1759 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 1760 MHD_PANIC ("Failed to acquire cleanup mutex\n");
1760 connection->resuming = MHD_YES; 1761 connection->resuming = MHD_YES;
1761 daemon->resuming = MHD_YES; 1762 daemon->resuming = MHD_YES;
@@ -1768,7 +1769,7 @@ MHD_resume_connection (struct MHD_Connection *connection)
1768#endif 1769#endif
1769 } 1770 }
1770 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1771 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1771 (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) ) 1772 (!MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
1772 MHD_PANIC ("Failed to release cleanup mutex\n"); 1773 MHD_PANIC ("Failed to release cleanup mutex\n");
1773} 1774}
1774 1775
@@ -1789,7 +1790,7 @@ resume_suspended_connections (struct MHD_Daemon *daemon)
1789 1790
1790 ret = MHD_NO; 1791 ret = MHD_NO;
1791 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1792 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1792 (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) ) 1793 (!MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) )
1793 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 1794 MHD_PANIC ("Failed to acquire cleanup mutex\n");
1794 if (MHD_NO != daemon->resuming) 1795 if (MHD_NO != daemon->resuming)
1795 next = daemon->suspended_connections_head; 1796 next = daemon->suspended_connections_head;
@@ -1845,7 +1846,7 @@ resume_suspended_connections (struct MHD_Daemon *daemon)
1845 pos->resuming = MHD_NO; 1846 pos->resuming = MHD_NO;
1846 } 1847 }
1847 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1848 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1848 (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) ) 1849 (!MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
1849 MHD_PANIC ("Failed to release cleanup mutex\n"); 1850 MHD_PANIC ("Failed to release cleanup mutex\n");
1850 return ret; 1851 return ret;
1851} 1852}
@@ -2069,7 +2070,7 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
2069 struct MHD_Connection *pos; 2070 struct MHD_Connection *pos;
2070 2071
2071 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 2072 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
2072 (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) ) 2073 (!MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) )
2073 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 2074 MHD_PANIC ("Failed to acquire cleanup mutex\n");
2074 while (NULL != (pos = daemon->cleanup_head)) 2075 while (NULL != (pos = daemon->cleanup_head))
2075 { 2076 {
@@ -2140,7 +2141,7 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
2140 free (pos); 2141 free (pos);
2141 } 2142 }
2142 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 2143 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
2143 (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) ) 2144 (!MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
2144 MHD_PANIC ("Failed to release cleanup mutex\n"); 2145 MHD_PANIC ("Failed to release cleanup mutex\n");
2145} 2146}
2146 2147
@@ -3856,7 +3857,7 @@ MHD_start_daemon_va (unsigned int flags,
3856 } 3857 }
3857 } 3858 }
3858 3859
3859 if (MHD_YES != MHD_mutex_create_ (&daemon->nnc_lock)) 3860 if (!MHD_mutex_init_ (&daemon->nnc_lock))
3860 { 3861 {
3861#ifdef HAVE_MESSAGES 3862#ifdef HAVE_MESSAGES
3862 MHD_DLOG (daemon, 3863 MHD_DLOG (daemon,
@@ -4184,7 +4185,7 @@ MHD_start_daemon_va (unsigned int flags,
4184 } 4185 }
4185#endif 4186#endif
4186 4187
4187 if (MHD_YES != MHD_mutex_create_ (&daemon->per_ip_connection_mutex)) 4188 if (!MHD_mutex_init_ (&daemon->per_ip_connection_mutex))
4188 { 4189 {
4189#ifdef HAVE_MESSAGES 4190#ifdef HAVE_MESSAGES
4190 MHD_DLOG (daemon, 4191 MHD_DLOG (daemon,
@@ -4195,7 +4196,7 @@ MHD_start_daemon_va (unsigned int flags,
4195 MHD_PANIC ("close failed\n"); 4196 MHD_PANIC ("close failed\n");
4196 goto free_and_fail; 4197 goto free_and_fail;
4197 } 4198 }
4198 if (MHD_YES != MHD_mutex_create_ (&daemon->cleanup_connection_mutex)) 4199 if (!MHD_mutex_init_ (&daemon->cleanup_connection_mutex))
4199 { 4200 {
4200#ifdef HAVE_MESSAGES 4201#ifdef HAVE_MESSAGES
4201 MHD_DLOG (daemon, 4202 MHD_DLOG (daemon,
@@ -4331,7 +4332,7 @@ MHD_start_daemon_va (unsigned int flags,
4331 goto thread_failed; 4332 goto thread_failed;
4332#endif 4333#endif
4333 /* Must init cleanup connection mutex for each worker */ 4334 /* Must init cleanup connection mutex for each worker */
4334 if (MHD_YES != MHD_mutex_create_ (&d->cleanup_connection_mutex)) 4335 if (!MHD_mutex_init_ (&d->cleanup_connection_mutex))
4335 { 4336 {
4336#ifdef HAVE_MESSAGES 4337#ifdef HAVE_MESSAGES
4337 MHD_DLOG (daemon, 4338 MHD_DLOG (daemon,
@@ -4466,7 +4467,7 @@ close_all_connections (struct MHD_Daemon *daemon)
4466 /* first, make sure all threads are aware of shutdown; need to 4467 /* first, make sure all threads are aware of shutdown; need to
4467 traverse DLLs in peace... */ 4468 traverse DLLs in peace... */
4468 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 4469 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
4469 (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) ) 4470 (!MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) )
4470 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 4471 MHD_PANIC ("Failed to acquire cleanup mutex\n");
4471 if (NULL != daemon->suspended_connections_head) 4472 if (NULL != daemon->suspended_connections_head)
4472 MHD_PANIC ("MHD_stop_daemon() called while we have suspended connections.\n"); 4473 MHD_PANIC ("MHD_stop_daemon() called while we have suspended connections.\n");
@@ -4481,7 +4482,7 @@ close_all_connections (struct MHD_Daemon *daemon)
4481#endif 4482#endif
4482 } 4483 }
4483 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 4484 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
4484 (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) ) 4485 (!MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
4485 MHD_PANIC ("Failed to release cleanup mutex\n"); 4486 MHD_PANIC ("Failed to release cleanup mutex\n");
4486 4487
4487 /* now, collect per-connection threads */ 4488 /* now, collect per-connection threads */
@@ -4928,7 +4929,7 @@ gcry_w32_mutex_init (void **ppmtx)
4928 4929
4929 if (NULL == *ppmtx) 4930 if (NULL == *ppmtx)
4930 return ENOMEM; 4931 return ENOMEM;
4931 if (MHD_YES != MHD_mutex_create_ ((MHD_mutex_*)*ppmtx)) 4932 if (!MHD_mutex_init_ ((MHD_mutex_*)*ppmtx))
4932 { 4933 {
4933 free (*ppmtx); 4934 free (*ppmtx);
4934 *ppmtx = NULL; 4935 *ppmtx = NULL;
@@ -4942,7 +4943,7 @@ gcry_w32_mutex_init (void **ppmtx)
4942static int 4943static int
4943gcry_w32_mutex_destroy (void **ppmtx) 4944gcry_w32_mutex_destroy (void **ppmtx)
4944{ 4945{
4945 int res = (MHD_YES == MHD_mutex_destroy_ ((MHD_mutex_*)*ppmtx)) ? 0 : 1; 4946 int res = (MHD_mutex_destroy_ ((MHD_mutex_*)*ppmtx)) ? 0 : 1;
4946 free (*ppmtx); 4947 free (*ppmtx);
4947 return res; 4948 return res;
4948} 4949}
@@ -4951,14 +4952,14 @@ gcry_w32_mutex_destroy (void **ppmtx)
4951static int 4952static int
4952gcry_w32_mutex_lock (void **ppmtx) 4953gcry_w32_mutex_lock (void **ppmtx)
4953{ 4954{
4954 return (MHD_YES == MHD_mutex_lock_ ((MHD_mutex_*)*ppmtx)) ? 0 : 1; 4955 return (MHD_mutex_lock_ ((MHD_mutex_*)*ppmtx)) ? 0 : 1;
4955} 4956}
4956 4957
4957 4958
4958static int 4959static int
4959gcry_w32_mutex_unlock (void **ppmtx) 4960gcry_w32_mutex_unlock (void **ppmtx)
4960{ 4961{
4961 return (MHD_YES == MHD_mutex_unlock_ ((MHD_mutex_*)*ppmtx)) ? 0 : 1; 4962 return (MHD_mutex_unlock_ ((MHD_mutex_*)*ppmtx)) ? 0 : 1;
4962} 4963}
4963 4964
4964 4965