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.c78
1 files changed, 39 insertions, 39 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index dafc75ef..2e3d8833 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -819,9 +819,10 @@ MHD_get_fdset2 (struct MHD_Daemon *daemon,
819 fd_setsize)) ) 819 fd_setsize)) )
820 result = MHD_NO; 820 result = MHD_NO;
821 821
822 for (pos = daemon->connections_head; NULL != pos; pos = posn) 822 /* Start from oldest connections. Make sense for W32 FDSETs. */
823 for (pos = daemon->connections_tail; NULL != pos; pos = posn)
823 { 824 {
824 posn = pos->next; 825 posn = pos->prev;
825 826
826 switch (pos->event_loop_info) 827 switch (pos->event_loop_info)
827 { 828 {
@@ -856,7 +857,7 @@ MHD_get_fdset2 (struct MHD_Daemon *daemon,
856 { 857 {
857 struct MHD_UpgradeResponseHandle *urh; 858 struct MHD_UpgradeResponseHandle *urh;
858 859
859 for (urh = daemon->urh_head; NULL != urh; urh = urh->next) 860 for (urh = daemon->urh_tail; NULL != urh; urh = urh->prev)
860 { 861 {
861 if (MHD_NO == 862 if (MHD_NO ==
862 urh_to_fdset (urh, 863 urh_to_fdset (urh,
@@ -2547,26 +2548,26 @@ static int
2547resume_suspended_connections (struct MHD_Daemon *daemon) 2548resume_suspended_connections (struct MHD_Daemon *daemon)
2548{ 2549{
2549 struct MHD_Connection *pos; 2550 struct MHD_Connection *pos;
2550 struct MHD_Connection *next = NULL; 2551 struct MHD_Connection *prev = NULL;
2551 int ret; 2552 int ret;
2552 2553
2553 ret = MHD_NO; 2554 ret = MHD_NO;
2554 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); 2555 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
2555 2556
2556 if (daemon->resuming) 2557 if (daemon->resuming)
2557 next = daemon->suspended_connections_head; 2558 prev = daemon->suspended_connections_tail;
2558 2559
2559 EXTRA_CHECK(NULL != next); 2560 EXTRA_CHECK(NULL != next);
2560 daemon->resuming = false; 2561 daemon->resuming = false;
2561 2562
2562 while (NULL != (pos = next)) 2563 while (NULL != (pos = prev))
2563 { 2564 {
2564#ifdef UPGRADE_SUPPORT 2565#ifdef UPGRADE_SUPPORT
2565 struct MHD_UpgradeResponseHandle * const urh = pos->urh; 2566 struct MHD_UpgradeResponseHandle * const urh = pos->urh;
2566#else /* ! UPGRADE_SUPPORT */ 2567#else /* ! UPGRADE_SUPPORT */
2567 static const void * const urh = NULL; 2568 static const void * const urh = NULL;
2568#endif /* ! UPGRADE_SUPPORT */ 2569#endif /* ! UPGRADE_SUPPORT */
2569 next = pos->next; 2570 prev = pos->prev;
2570 if ( (! pos->resuming) 2571 if ( (! pos->resuming)
2571#ifdef UPGRADE_SUPPORT 2572#ifdef UPGRADE_SUPPORT
2572 || ( (NULL != urh) && 2573 || ( (NULL != urh) &&
@@ -2855,7 +2856,7 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
2855 struct MHD_Connection *pos; 2856 struct MHD_Connection *pos;
2856 2857
2857 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); 2858 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
2858 while (NULL != (pos = daemon->cleanup_head)) 2859 while (NULL != (pos = daemon->cleanup_tail))
2859 { 2860 {
2860 DLL_remove (daemon->cleanup_head, 2861 DLL_remove (daemon->cleanup_head,
2861 daemon->cleanup_tail, 2862 daemon->cleanup_tail,
@@ -2985,7 +2986,7 @@ MHD_get_timeout (struct MHD_Daemon *daemon,
2985 2986
2986 have_timeout = false;; 2987 have_timeout = false;;
2987 earliest_deadline = 0; /* avoid compiler warnings */ 2988 earliest_deadline = 0; /* avoid compiler warnings */
2988 for (pos = daemon->manual_timeout_head; NULL != pos; pos = pos->nextX) 2989 for (pos = daemon->manual_timeout_tail; NULL != pos; pos = pos->prevX)
2989 { 2990 {
2990 if (0 != pos->connection_timeout) 2991 if (0 != pos->connection_timeout)
2991 { 2992 {
@@ -3050,7 +3051,7 @@ MHD_run_from_select (struct MHD_Daemon *daemon,
3050{ 3051{
3051 MHD_socket ds; 3052 MHD_socket ds;
3052 struct MHD_Connection *pos; 3053 struct MHD_Connection *pos;
3053 struct MHD_Connection *next; 3054 struct MHD_Connection *prev;
3054#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 3055#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
3055 struct MHD_UpgradeResponseHandle *urh; 3056 struct MHD_UpgradeResponseHandle *urh;
3056 struct MHD_UpgradeResponseHandle *urhn; 3057 struct MHD_UpgradeResponseHandle *urhn;
@@ -3099,10 +3100,10 @@ MHD_run_from_select (struct MHD_Daemon *daemon,
3099 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 3100 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
3100 { 3101 {
3101 /* do not have a thread per connection, process all connections now */ 3102 /* do not have a thread per connection, process all connections now */
3102 next = daemon->connections_head; 3103 prev = daemon->connections_tail;
3103 while (NULL != (pos = next)) 3104 while (NULL != (pos = prev))
3104 { 3105 {
3105 next = pos->next; 3106 prev = pos->next;
3106 ds = pos->socket_fd; 3107 ds = pos->socket_fd;
3107 if (MHD_INVALID_SOCKET == ds) 3108 if (MHD_INVALID_SOCKET == ds)
3108 continue; 3109 continue;
@@ -3118,9 +3119,9 @@ MHD_run_from_select (struct MHD_Daemon *daemon,
3118 3119
3119#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 3120#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
3120 /* handle upgraded HTTPS connections */ 3121 /* handle upgraded HTTPS connections */
3121 for (urh = daemon->urh_head; NULL != urh; urh = urhn) 3122 for (urh = daemon->urh_tail; NULL != urh; urh = urhn)
3122 { 3123 {
3123 urhn = urh->next; 3124 urhn = urh->prev;
3124 /* update urh state based on select() output */ 3125 /* update urh state based on select() output */
3125 urh_from_fdset (urh, 3126 urh_from_fdset (urh,
3126 read_fd_set, 3127 read_fd_set,
@@ -3325,7 +3326,7 @@ MHD_poll_all (struct MHD_Daemon *daemon,
3325{ 3326{
3326 unsigned int num_connections; 3327 unsigned int num_connections;
3327 struct MHD_Connection *pos; 3328 struct MHD_Connection *pos;
3328 struct MHD_Connection *next; 3329 struct MHD_Connection *prev;
3329#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 3330#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
3330 struct MHD_UpgradeResponseHandle *urh; 3331 struct MHD_UpgradeResponseHandle *urh;
3331 struct MHD_UpgradeResponseHandle *urhn; 3332 struct MHD_UpgradeResponseHandle *urhn;
@@ -3396,7 +3397,7 @@ MHD_poll_all (struct MHD_Daemon *daemon,
3396 timeout = (ltimeout > INT_MAX) ? INT_MAX : (int) ltimeout; 3397 timeout = (ltimeout > INT_MAX) ? INT_MAX : (int) ltimeout;
3397 3398
3398 i = 0; 3399 i = 0;
3399 for (pos = daemon->connections_head; NULL != pos; pos = pos->next) 3400 for (pos = daemon->connections_tail; NULL != pos; pos = pos->prev)
3400 { 3401 {
3401 p[poll_server+i].fd = pos->socket_fd; 3402 p[poll_server+i].fd = pos->socket_fd;
3402 switch (pos->event_loop_info) 3403 switch (pos->event_loop_info)
@@ -3417,7 +3418,7 @@ MHD_poll_all (struct MHD_Daemon *daemon,
3417 i++; 3418 i++;
3418 } 3419 }
3419#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 3420#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
3420 for (urh = daemon->urh_head; NULL != urh; urh = urh->next) 3421 for (urh = daemon->urh_tail; NULL != urh; urh = urh->prev)
3421 { 3422 {
3422 p[poll_server+i].fd = urh->connection->socket_fd; 3423 p[poll_server+i].fd = urh->connection->socket_fd;
3423 if (urh->in_buffer_used < urh->in_buffer_size) 3424 if (urh->in_buffer_used < urh->in_buffer_size)
@@ -3474,10 +3475,10 @@ MHD_poll_all (struct MHD_Daemon *daemon,
3474 return MHD_NO; 3475 return MHD_NO;
3475 } 3476 }
3476 i = 0; 3477 i = 0;
3477 next = daemon->connections_head; 3478 prev = daemon->connections_tail;
3478 while (NULL != (pos = next)) 3479 while (NULL != (pos = prev))
3479 { 3480 {
3480 next = pos->next; 3481 prev = pos->prev;
3481 /* first, sanity checks */ 3482 /* first, sanity checks */
3482 if (i >= num_connections) 3483 if (i >= num_connections)
3483 break; /* connection list changed somehow, retry later ... */ 3484 break; /* connection list changed somehow, retry later ... */
@@ -3490,14 +3491,14 @@ MHD_poll_all (struct MHD_Daemon *daemon,
3490 i++; 3491 i++;
3491 } 3492 }
3492#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 3493#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
3493 for (urh = daemon->urh_head; NULL != urh; urh = urhn) 3494 for (urh = daemon->urh_tail; NULL != urh; urh = urhn)
3494 { 3495 {
3495 if (i >= num_connections) 3496 if (i >= num_connections)
3496 break; /* connection list changed somehow, retry later ... */ 3497 break; /* connection list changed somehow, retry later ... */
3497 3498
3498 /* Get next connection here as connection can be removed 3499 /* Get next connection here as connection can be removed
3499 * from 'daemon->urh_head' list. */ 3500 * from 'daemon->urh_head' list. */
3500 urhn = urh->next; 3501 urhn = urh->prev;
3501 /* Check for fd mismatch. FIXME: required for safety? */ 3502 /* Check for fd mismatch. FIXME: required for safety? */
3502 if (p[poll_server+i].fd == urh->connection->socket_fd) 3503 if (p[poll_server+i].fd == urh->connection->socket_fd)
3503 { 3504 {
@@ -3755,7 +3756,6 @@ MHD_epoll (struct MHD_Daemon *daemon,
3755 static const char *upgrade_marker = "upgrade_ptr"; 3756 static const char *upgrade_marker = "upgrade_ptr";
3756#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ 3757#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */
3757 struct MHD_Connection *pos; 3758 struct MHD_Connection *pos;
3758 struct MHD_Connection *next;
3759 struct MHD_Connection *prev; 3759 struct MHD_Connection *prev;
3760 struct epoll_event events[MAX_EVENTS]; 3760 struct epoll_event events[MAX_EVENTS];
3761 struct epoll_event event; 3761 struct epoll_event event;
@@ -4018,20 +4018,20 @@ MHD_epoll (struct MHD_Daemon *daemon,
4018 4018
4019 Connections with custom timeouts must all be looked at, as we 4019 Connections with custom timeouts must all be looked at, as we
4020 do not bother to sort that (presumably very short) list. */ 4020 do not bother to sort that (presumably very short) list. */
4021 next = daemon->manual_timeout_head; 4021 prev = daemon->manual_timeout_tail;
4022 while (NULL != (pos = next)) 4022 while (NULL != (pos = prev))
4023 { 4023 {
4024 next = pos->nextX; 4024 prev = pos->prevX;
4025 pos->idle_handler (pos); 4025 pos->idle_handler (pos);
4026 } 4026 }
4027 /* Connections with the default timeout are sorted by prepending 4027 /* Connections with the default timeout are sorted by prepending
4028 them to the head of the list whenever we touch the connection; 4028 them to the head of the list whenever we touch the connection;
4029 thus it suffices to iterate from the tail until the first 4029 thus it suffices to iterate from the tail until the first
4030 connection is NOT timed out */ 4030 connection is NOT timed out */
4031 next = daemon->normal_timeout_tail; 4031 prev = daemon->normal_timeout_tail;
4032 while (NULL != (pos = next)) 4032 while (NULL != (pos = prev))
4033 { 4033 {
4034 next = pos->prevX; 4034 prev = pos->prevX;
4035 pos->idle_handler (pos); 4035 pos->idle_handler (pos);
4036 if (MHD_CONNECTION_CLOSED != pos->state) 4036 if (MHD_CONNECTION_CLOSED != pos->state)
4037 break; /* sorted by timeout, no need to visit the rest! */ 4037 break; /* sorted by timeout, no need to visit the rest! */
@@ -5657,9 +5657,9 @@ close_all_connections (struct MHD_Daemon *daemon)
5657 5657
5658 /* give upgraded HTTPS connections a chance to finish */ 5658 /* give upgraded HTTPS connections a chance to finish */
5659 /* 'daemon->urh_head' is not used in thread-per-connection mode. */ 5659 /* 'daemon->urh_head' is not used in thread-per-connection mode. */
5660 for (urh = daemon->urh_head; NULL != urh; urh = urhn) 5660 for (urh = daemon->urh_tail; NULL != urh; urh = urhn)
5661 { 5661 {
5662 urhn = urh->next; 5662 urhn = urh->prev;
5663 /* call generic forwarding function for passing data 5663 /* call generic forwarding function for passing data
5664 with chance to detect that application is done. */ 5664 with chance to detect that application is done. */
5665 process_urh (urh); 5665 process_urh (urh);
@@ -5687,7 +5687,7 @@ close_all_connections (struct MHD_Daemon *daemon)
5687 { 5687 {
5688 struct MHD_Connection * susp; 5688 struct MHD_Connection * susp;
5689 5689
5690 susp = daemon->suspended_connections_head; 5690 susp = daemon->suspended_connections_tail;
5691 while (NULL != susp) 5691 while (NULL != susp)
5692 { 5692 {
5693 if (NULL == susp->urh) /* "Upgraded" connection? */ 5693 if (NULL == susp->urh) /* "Upgraded" connection? */
@@ -5716,14 +5716,14 @@ close_all_connections (struct MHD_Daemon *daemon)
5716 susp->resuming = true; 5716 susp->resuming = true;
5717 daemon->resuming = true; 5717 daemon->resuming = true;
5718 } 5718 }
5719 susp = susp->next; 5719 susp = susp->prev;
5720 } 5720 }
5721 } 5721 }
5722 else /* This 'else' is combined with next 'if' */ 5722 else /* This 'else' is combined with next 'if' */
5723#endif /* UPGRADE_SUPPORT */ 5723#endif /* UPGRADE_SUPPORT */
5724 if (NULL != daemon->suspended_connections_head) 5724 if (NULL != daemon->suspended_connections_head)
5725 MHD_PANIC (_("MHD_stop_daemon() called while we have suspended connections.\n")); 5725 MHD_PANIC (_("MHD_stop_daemon() called while we have suspended connections.\n"));
5726 for (pos = daemon->connections_head; NULL != pos; pos = pos->next) 5726 for (pos = daemon->connections_tail; NULL != pos; pos = pos->prev)
5727 { 5727 {
5728 shutdown (pos->socket_fd, 5728 shutdown (pos->socket_fd,
5729 SHUT_RDWR); 5729 SHUT_RDWR);
@@ -5738,7 +5738,7 @@ close_all_connections (struct MHD_Daemon *daemon)
5738 /* now, collect per-connection threads */ 5738 /* now, collect per-connection threads */
5739 if (used_thr_p_c) 5739 if (used_thr_p_c)
5740 { 5740 {
5741 pos = daemon->connections_head; 5741 pos = daemon->connections_tail;
5742 while (NULL != pos) 5742 while (NULL != pos)
5743 { 5743 {
5744 if (! pos->thread_joined) 5744 if (! pos->thread_joined)
@@ -5750,10 +5750,10 @@ close_all_connections (struct MHD_Daemon *daemon)
5750 pos->thread_joined = true; 5750 pos->thread_joined = true;
5751 /* The thread may have concurrently modified the DLL, 5751 /* The thread may have concurrently modified the DLL,
5752 need to restart from the beginning */ 5752 need to restart from the beginning */
5753 pos = daemon->connections_head; 5753 pos = daemon->connections_tail;
5754 continue; 5754 continue;
5755 } 5755 }
5756 pos = pos->next; 5756 pos = pos->prev;
5757 } 5757 }
5758 } 5758 }
5759 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 5759 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
@@ -5771,7 +5771,7 @@ close_all_connections (struct MHD_Daemon *daemon)
5771#endif /* UPGRADE_SUPPORT */ 5771#endif /* UPGRADE_SUPPORT */
5772 5772
5773 /* now that we're alone, move everyone to cleanup */ 5773 /* now that we're alone, move everyone to cleanup */
5774 while (NULL != (pos = daemon->connections_head)) 5774 while (NULL != (pos = daemon->connections_tail))
5775 { 5775 {
5776 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 5776 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
5777 (! pos->thread_joined) ) 5777 (! pos->thread_joined) )