aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd')
-rw-r--r--src/microhttpd/daemon.c36
1 files changed, 22 insertions, 14 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index f93fea2e..5af6bd60 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -957,7 +957,7 @@ MHD_handle_connection (void *data)
957 break; 957 break;
958 } 958 }
959#if WINDOWS 959#if WINDOWS
960 /* drain signaling pipe */ 960 /* drain signaling pipe before other processing */
961 if ( (MHD_INVALID_PIPE_ != spipe) && 961 if ( (MHD_INVALID_PIPE_ != spipe) &&
962 (FD_ISSET (spipe, &rs)) ) 962 (FD_ISSET (spipe, &rs)) )
963 MHD_pipe_drain_ (spipe); 963 MHD_pipe_drain_ (spipe);
@@ -1029,7 +1029,7 @@ MHD_handle_connection (void *data)
1029 break; 1029 break;
1030 } 1030 }
1031#if WINDOWS 1031#if WINDOWS
1032 /* drain signaling pipe */ 1032 /* drain signaling pipe before other processing */
1033 if ( (MHD_INVALID_PIPE_ != spipe) && 1033 if ( (MHD_INVALID_PIPE_ != spipe) &&
1034 (0 != (p[1].revents & (POLLERR | POLLHUP))) ) 1034 (0 != (p[1].revents & (POLLERR | POLLHUP))) )
1035 MHD_pipe_drain_ (spipe); 1035 MHD_pipe_drain_ (spipe);
@@ -1821,9 +1821,11 @@ resume_suspended_connections (struct MHD_Daemon *daemon)
1821 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1821 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1822 (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) ) 1822 (MHD_YES != MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) )
1823 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 1823 MHD_PANIC ("Failed to acquire cleanup mutex\n");
1824 if (MHD_YES == daemon->resuming) 1824 if (MHD_NO != daemon->resuming)
1825 next = daemon->suspended_connections_head; 1825 next = daemon->suspended_connections_head;
1826 1826
1827 if (NULL != next)
1828 daemon->resuming = MHD_NO;
1827 while (NULL != (pos = next)) 1829 while (NULL != (pos = next))
1828 { 1830 {
1829 next = pos->next; 1831 next = pos->next;
@@ -1864,7 +1866,6 @@ resume_suspended_connections (struct MHD_Daemon *daemon)
1864 pos->suspended = MHD_NO; 1866 pos->suspended = MHD_NO;
1865 pos->resuming = MHD_NO; 1867 pos->resuming = MHD_NO;
1866 } 1868 }
1867 daemon->resuming = MHD_NO;
1868 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1869 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1869 (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) ) 1870 (MHD_YES != MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) )
1870 MHD_PANIC ("Failed to release cleanup mutex\n"); 1871 MHD_PANIC ("Failed to release cleanup mutex\n");
@@ -2262,6 +2263,13 @@ MHD_run_from_select (struct MHD_Daemon *daemon,
2262 unsigned int mask = MHD_USE_SUSPEND_RESUME | MHD_USE_EPOLL_INTERNALLY_LINUX_ONLY | 2263 unsigned int mask = MHD_USE_SUSPEND_RESUME | MHD_USE_EPOLL_INTERNALLY_LINUX_ONLY |
2263 MHD_USE_SELECT_INTERNALLY | MHD_USE_POLL_INTERNALLY | MHD_USE_THREAD_PER_CONNECTION; 2264 MHD_USE_SELECT_INTERNALLY | MHD_USE_POLL_INTERNALLY | MHD_USE_THREAD_PER_CONNECTION;
2264 2265
2266 /* drain signaling pipe to avoid spinning select */
2267 /* Do it before any other processing so new signals
2268 will trigger select again and will be processed */
2269 if ((MHD_INVALID_PIPE_ != daemon->wpipe[0]) &&
2270 (FD_ISSET (daemon->wpipe[0], read_fd_set)))
2271 MHD_pipe_drain_ (daemon->wpipe[0]);
2272
2265 /* Resuming external connections when using an extern mainloop */ 2273 /* Resuming external connections when using an extern mainloop */
2266 if (MHD_USE_SUSPEND_RESUME == (daemon->options & mask)) 2274 if (MHD_USE_SUSPEND_RESUME == (daemon->options & mask))
2267 resume_suspended_connections (daemon); 2275 resume_suspended_connections (daemon);
@@ -2283,10 +2291,6 @@ MHD_run_from_select (struct MHD_Daemon *daemon,
2283 if ( (MHD_INVALID_SOCKET != (ds = daemon->socket_fd)) && 2291 if ( (MHD_INVALID_SOCKET != (ds = daemon->socket_fd)) &&
2284 (FD_ISSET (ds, read_fd_set)) ) 2292 (FD_ISSET (ds, read_fd_set)) )
2285 (void) MHD_accept_connection (daemon); 2293 (void) MHD_accept_connection (daemon);
2286 /* drain signaling pipe to avoid spinning select */
2287 if ( (MHD_INVALID_PIPE_ != daemon->wpipe[0]) &&
2288 (FD_ISSET (daemon->wpipe[0], read_fd_set)) )
2289 MHD_pipe_drain_ (daemon->wpipe[0]);
2290 2294
2291 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 2295 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
2292 { 2296 {
@@ -2591,6 +2595,13 @@ MHD_poll_all (struct MHD_Daemon *daemon,
2591 free(p); 2595 free(p);
2592 return MHD_NO; 2596 return MHD_NO;
2593 } 2597 }
2598 /* handle pipe FD */
2599 /* do it before any other processing so
2600 new signals will be processed in next loop */
2601 if ( (-1 != poll_pipe) &&
2602 (0 != (p[poll_pipe].revents & POLLIN)) )
2603 MHD_pipe_drain_ (daemon->wpipe[0]);
2604
2594 /* handle shutdown */ 2605 /* handle shutdown */
2595 if (MHD_YES == daemon->shutdown) 2606 if (MHD_YES == daemon->shutdown)
2596 { 2607 {
@@ -2645,11 +2656,6 @@ MHD_poll_all (struct MHD_Daemon *daemon,
2645 (0 != (p[poll_listen].revents & POLLIN)) ) 2656 (0 != (p[poll_listen].revents & POLLIN)) )
2646 (void) MHD_accept_connection (daemon); 2657 (void) MHD_accept_connection (daemon);
2647 2658
2648 /* handle pipe FD */
2649 if ( (-1 != poll_pipe) &&
2650 (0 != (p[poll_pipe].revents & POLLIN)) )
2651 MHD_pipe_drain_ (daemon->wpipe[0]);
2652
2653 free(p); 2659 free(p);
2654 } 2660 }
2655 return MHD_YES; 2661 return MHD_YES;
@@ -2857,6 +2863,8 @@ MHD_epoll (struct MHD_Daemon *daemon,
2857 if ( (MHD_INVALID_PIPE_ != daemon->wpipe[0]) && 2863 if ( (MHD_INVALID_PIPE_ != daemon->wpipe[0]) &&
2858 (daemon->wpipe[0] == events[i].data.fd) ) 2864 (daemon->wpipe[0] == events[i].data.fd) )
2859 { 2865 {
2866 /* It's OK to drain pipe here as all external
2867 conditions will be processed later. */
2860 MHD_pipe_drain_ (daemon->wpipe[0]); 2868 MHD_pipe_drain_ (daemon->wpipe[0]);
2861 continue; 2869 continue;
2862 } 2870 }