aboutsummaryrefslogtreecommitdiff
path: root/src/lib/request_resume.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/request_resume.c')
-rw-r--r--src/lib/request_resume.c185
1 files changed, 95 insertions, 90 deletions
diff --git a/src/lib/request_resume.c b/src/lib/request_resume.c
index a69107b9..be513f53 100644
--- a/src/lib/request_resume.c
+++ b/src/lib/request_resume.c
@@ -45,21 +45,23 @@ MHD_request_resume (struct MHD_Request *request)
45 struct MHD_Daemon *daemon = request->daemon; 45 struct MHD_Daemon *daemon = request->daemon;
46 46
47 if (daemon->disallow_suspend_resume) 47 if (daemon->disallow_suspend_resume)
48 MHD_PANIC (_("Cannot resume connections without enabling MHD_ALLOW_SUSPEND_RESUME!\n")); 48 MHD_PANIC (_ (
49 "Cannot resume connections without enabling MHD_ALLOW_SUSPEND_RESUME!\n"));
49 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); 50 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
50 request->connection->resuming = true; 51 request->connection->resuming = true;
51 daemon->resuming = true; 52 daemon->resuming = true;
52 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 53 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
53 if ( (MHD_ITC_IS_VALID_(daemon->itc)) && 54 if ( (MHD_ITC_IS_VALID_ (daemon->itc)) &&
54 (! MHD_itc_activate_ (daemon->itc, 55 (! MHD_itc_activate_ (daemon->itc,
55 "r")) ) 56 "r")) )
56 { 57 {
57#ifdef HAVE_MESSAGES 58#ifdef HAVE_MESSAGES
58 MHD_DLOG (daemon, 59 MHD_DLOG (daemon,
59 MHD_SC_ITC_USE_FAILED, 60 MHD_SC_ITC_USE_FAILED,
60 _("Failed to signal resume via inter-thread communication channel.")); 61 _ (
62 "Failed to signal resume via inter-thread communication channel."));
61#endif 63#endif
62 } 64 }
63} 65}
64 66
65 67
@@ -80,115 +82,118 @@ MHD_resume_suspended_connections_ (struct MHD_Daemon *daemon)
80 struct MHD_Connection *pos; 82 struct MHD_Connection *pos;
81 struct MHD_Connection *prev = NULL; 83 struct MHD_Connection *prev = NULL;
82 bool ret; 84 bool ret;
83 const bool used_thr_p_c = (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode); 85 const bool used_thr_p_c = (MHD_TM_THREAD_PER_CONNECTION ==
86 daemon->threading_mode);
84 87
85 mhd_assert (NULL == daemon->worker_pool); 88 mhd_assert (NULL == daemon->worker_pool);
86 ret = false; 89 ret = false;
87 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); 90 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
88 91
89 if (daemon->resuming) 92 if (daemon->resuming)
90 { 93 {
91 prev = daemon->suspended_connections_tail; 94 prev = daemon->suspended_connections_tail;
92 /* During shutdown check for resuming is forced. */ 95 /* During shutdown check for resuming is forced. */
93 mhd_assert((NULL != prev) || (daemon->shutdown)); 96 mhd_assert ((NULL != prev) || (daemon->shutdown));
94 } 97 }
95 98
96 daemon->resuming = false; 99 daemon->resuming = false;
97 100
98 while (NULL != (pos = prev)) 101 while (NULL != (pos = prev))
99 { 102 {
100#ifdef UPGRADE_SUPPORT 103#ifdef UPGRADE_SUPPORT
101 struct MHD_UpgradeResponseHandle * const urh = pos->request.urh; 104 struct MHD_UpgradeResponseHandle *const urh = pos->request.urh;
102#else /* ! UPGRADE_SUPPORT */ 105#else /* ! UPGRADE_SUPPORT */
103 static const void * const urh = NULL; 106 static const void *const urh = NULL;
104#endif /* ! UPGRADE_SUPPORT */ 107#endif /* ! UPGRADE_SUPPORT */
105 prev = pos->prev; 108 prev = pos->prev;
106 if ( (! pos->resuming) 109 if ( (! pos->resuming)
107#ifdef UPGRADE_SUPPORT 110#ifdef UPGRADE_SUPPORT
108 || ( (NULL != urh) && 111 || ( (NULL != urh) &&
109 ( (! urh->was_closed) || 112 ( (! urh->was_closed) ||
110 (! urh->clean_ready) ) ) 113 (! urh->clean_ready) ) )
111#endif /* UPGRADE_SUPPORT */ 114#endif /* UPGRADE_SUPPORT */
112 ) 115 )
113 continue; 116 continue;
114 ret = true; 117 ret = true;
115 mhd_assert (pos->suspended); 118 mhd_assert (pos->suspended);
116 DLL_remove (daemon->suspended_connections_head, 119 DLL_remove (daemon->suspended_connections_head,
117 daemon->suspended_connections_tail, 120 daemon->suspended_connections_tail,
121 pos);
122 pos->suspended = false;
123 if (NULL == urh)
124 {
125 DLL_insert (daemon->connections_head,
126 daemon->connections_tail,
118 pos); 127 pos);
119 pos->suspended = false; 128 if (! used_thr_p_c)
120 if (NULL == urh) 129 {
121 { 130 /* Reset timeout timer on resume. */
122 DLL_insert (daemon->connections_head, 131 if (0 != pos->connection_timeout)
123 daemon->connections_tail, 132 pos->last_activity = MHD_monotonic_sec_counter ();
124 pos); 133
125 if (! used_thr_p_c) 134 if (pos->connection_timeout == daemon->connection_default_timeout)
126 { 135 XDLL_insert (daemon->normal_timeout_head,
127 /* Reset timeout timer on resume. */ 136 daemon->normal_timeout_tail,
128 if (0 != pos->connection_timeout) 137 pos);
129 pos->last_activity = MHD_monotonic_sec_counter(); 138 else
130 139 XDLL_insert (daemon->manual_timeout_head,
131 if (pos->connection_timeout == daemon->connection_default_timeout) 140 daemon->manual_timeout_tail,
132 XDLL_insert (daemon->normal_timeout_head, 141 pos);
133 daemon->normal_timeout_tail, 142 }
134 pos);
135 else
136 XDLL_insert (daemon->manual_timeout_head,
137 daemon->manual_timeout_tail,
138 pos);
139 }
140#ifdef EPOLL_SUPPORT 143#ifdef EPOLL_SUPPORT
141 if (MHD_ELS_EPOLL == daemon->event_loop_syscall) 144 if (MHD_ELS_EPOLL == daemon->event_loop_syscall)
142 { 145 {
143 if (0 != (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL)) 146 if (0 != (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL))
144 MHD_PANIC ("Resumed connection was already in EREADY set\n"); 147 MHD_PANIC ("Resumed connection was already in EREADY set\n");
145 /* we always mark resumed connections as ready, as we 148 /* we always mark resumed connections as ready, as we
146 might have missed the edge poll event during suspension */ 149 might have missed the edge poll event during suspension */
147 EDLL_insert (daemon->eready_head, 150 EDLL_insert (daemon->eready_head,
148 daemon->eready_tail, 151 daemon->eready_tail,
149 pos); 152 pos);
150 pos->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL | \ 153 pos->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL \
151 MHD_EPOLL_STATE_READ_READY | MHD_EPOLL_STATE_WRITE_READY; 154 | MHD_EPOLL_STATE_READ_READY
152 pos->epoll_state &= ~MHD_EPOLL_STATE_SUSPENDED; 155 | MHD_EPOLL_STATE_WRITE_READY;
153 } 156 pos->epoll_state &= ~MHD_EPOLL_STATE_SUSPENDED;
157 }
154#endif 158#endif
155 } 159 }
156#ifdef UPGRADE_SUPPORT 160#ifdef UPGRADE_SUPPORT
157 else 161 else
158 { 162 {
159 struct MHD_Response *response = pos->request.response; 163 struct MHD_Response *response = pos->request.response;
160 164
161 /* Data forwarding was finished (for TLS connections) AND 165 /* Data forwarding was finished (for TLS connections) AND
162 * application was closed upgraded connection. 166 * application was closed upgraded connection.
163 * Insert connection into cleanup list. */ 167 * Insert connection into cleanup list. */
164 if ( (NULL != response) && 168 if ( (NULL != response) &&
165 (MHD_TM_THREAD_PER_CONNECTION != daemon->threading_mode) && 169 (MHD_TM_THREAD_PER_CONNECTION != daemon->threading_mode) &&
166 (NULL != response->termination_cb) ) 170 (NULL != response->termination_cb) )
167 response->termination_cb (response->termination_cb_cls, 171 response->termination_cb (response->termination_cb_cls,
168 MHD_REQUEST_TERMINATED_COMPLETED_OK, 172 MHD_REQUEST_TERMINATED_COMPLETED_OK,
169 &pos->request.client_context); 173 &pos->request.client_context);
170 DLL_insert (daemon->cleanup_head, 174 DLL_insert (daemon->cleanup_head,
171 daemon->cleanup_tail, 175 daemon->cleanup_tail,
172 pos); 176 pos);
173 177
174 }
175#endif /* UPGRADE_SUPPORT */
176 pos->resuming = false;
177 } 178 }
179#endif /* UPGRADE_SUPPORT */
180 pos->resuming = false;
181 }
178 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 182 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
179 if ( (used_thr_p_c) && 183 if ( (used_thr_p_c) &&
180 (ret) ) 184 (ret) )
181 { /* Wake up suspended connections. */ 185 { /* Wake up suspended connections. */
182 if (! MHD_itc_activate_(daemon->itc, 186 if (! MHD_itc_activate_ (daemon->itc,
183 "w")) 187 "w"))
184 { 188 {
185#ifdef HAVE_MESSAGES 189#ifdef HAVE_MESSAGES
186 MHD_DLOG (daemon, 190 MHD_DLOG (daemon,
187 MHD_SC_ITC_USE_FAILED, 191 MHD_SC_ITC_USE_FAILED,
188 _("Failed to signal resume of connection via inter-thread communication channel.")); 192 _ (
193 "Failed to signal resume of connection via inter-thread communication channel."));
189#endif 194#endif
190 }
191 } 195 }
196 }
192 return ret; 197 return ret;
193} 198}
194 199