diff options
Diffstat (limited to 'src/lib/daemon_poll.c')
-rw-r--r-- | src/lib/daemon_poll.c | 368 |
1 files changed, 185 insertions, 183 deletions
diff --git a/src/lib/daemon_poll.c b/src/lib/daemon_poll.c index 80599e93..1fea9fd6 100644 --- a/src/lib/daemon_poll.c +++ b/src/lib/daemon_poll.c | |||
@@ -45,7 +45,7 @@ | |||
45 | */ | 45 | */ |
46 | static void | 46 | static void |
47 | urh_update_pollfd (struct MHD_UpgradeResponseHandle *urh, | 47 | urh_update_pollfd (struct MHD_UpgradeResponseHandle *urh, |
48 | struct pollfd p[2]) | 48 | struct pollfd p[2]) |
49 | { | 49 | { |
50 | p[0].events = 0; | 50 | p[0].events = 0; |
51 | p[1].events = 0; | 51 | p[1].events = 0; |
@@ -86,12 +86,12 @@ urh_update_pollfd (struct MHD_UpgradeResponseHandle *urh, | |||
86 | */ | 86 | */ |
87 | static void | 87 | static void |
88 | urh_to_pollfd (struct MHD_UpgradeResponseHandle *urh, | 88 | urh_to_pollfd (struct MHD_UpgradeResponseHandle *urh, |
89 | struct pollfd p[2]) | 89 | struct pollfd p[2]) |
90 | { | 90 | { |
91 | p[0].fd = urh->connection->socket_fd; | 91 | p[0].fd = urh->connection->socket_fd; |
92 | p[1].fd = urh->mhd.socket; | 92 | p[1].fd = urh->mhd.socket; |
93 | urh_update_pollfd (urh, | 93 | urh_update_pollfd (urh, |
94 | p); | 94 | p); |
95 | } | 95 | } |
96 | 96 | ||
97 | 97 | ||
@@ -102,7 +102,7 @@ urh_to_pollfd (struct MHD_UpgradeResponseHandle *urh, | |||
102 | */ | 102 | */ |
103 | static void | 103 | static void |
104 | urh_from_pollfd (struct MHD_UpgradeResponseHandle *urh, | 104 | urh_from_pollfd (struct MHD_UpgradeResponseHandle *urh, |
105 | struct pollfd p[2]) | 105 | struct pollfd p[2]) |
106 | { | 106 | { |
107 | /* Reset read/write ready, preserve error state. */ | 107 | /* Reset read/write ready, preserve error state. */ |
108 | urh->app.celi &= (~MHD_EPOLL_STATE_READ_READY & ~MHD_EPOLL_STATE_WRITE_READY); | 108 | urh->app.celi &= (~MHD_EPOLL_STATE_READ_READY & ~MHD_EPOLL_STATE_WRITE_READY); |
@@ -138,7 +138,7 @@ urh_from_pollfd (struct MHD_UpgradeResponseHandle *urh, | |||
138 | */ | 138 | */ |
139 | enum MHD_StatusCode | 139 | enum MHD_StatusCode |
140 | MHD_daemon_poll_all_ (struct MHD_Daemon *daemon, | 140 | MHD_daemon_poll_all_ (struct MHD_Daemon *daemon, |
141 | bool may_block) | 141 | bool may_block) |
142 | { | 142 | { |
143 | unsigned int num_connections; | 143 | unsigned int num_connections; |
144 | struct MHD_Connection *pos; | 144 | struct MHD_Connection *pos; |
@@ -171,103 +171,103 @@ MHD_daemon_poll_all_ (struct MHD_Daemon *daemon, | |||
171 | MHD_socket ls; | 171 | MHD_socket ls; |
172 | 172 | ||
173 | p = MHD_calloc_ ((2 + num_connections), | 173 | p = MHD_calloc_ ((2 + num_connections), |
174 | sizeof (struct pollfd)); | 174 | sizeof (struct pollfd)); |
175 | if (NULL == p) | 175 | if (NULL == p) |
176 | { | 176 | { |
177 | #ifdef HAVE_MESSAGES | 177 | #ifdef HAVE_MESSAGES |
178 | MHD_DLOG (daemon, | 178 | MHD_DLOG (daemon, |
179 | MHD_SC_POLL_MALLOC_FAILURE, | 179 | MHD_SC_POLL_MALLOC_FAILURE, |
180 | _("Error allocating memory: %s\n"), | 180 | _ ("Error allocating memory: %s\n"), |
181 | MHD_strerror_(errno)); | 181 | MHD_strerror_ (errno)); |
182 | #endif | 182 | #endif |
183 | return MHD_SC_POLL_MALLOC_FAILURE; | 183 | return MHD_SC_POLL_MALLOC_FAILURE; |
184 | } | 184 | } |
185 | poll_server = 0; | 185 | poll_server = 0; |
186 | poll_listen = -1; | 186 | poll_listen = -1; |
187 | if ( (MHD_INVALID_SOCKET != (ls = daemon->listen_socket)) && | 187 | if ( (MHD_INVALID_SOCKET != (ls = daemon->listen_socket)) && |
188 | (! daemon->was_quiesced) && | 188 | (! daemon->was_quiesced) && |
189 | (daemon->connections < daemon->global_connection_limit) && | 189 | (daemon->connections < daemon->global_connection_limit) && |
190 | (! daemon->at_limit) ) | 190 | (! daemon->at_limit) ) |
191 | { | 191 | { |
192 | /* only listen if we are not at the connection limit */ | 192 | /* only listen if we are not at the connection limit */ |
193 | p[poll_server].fd = ls; | 193 | p[poll_server].fd = ls; |
194 | p[poll_server].events = POLLIN; | 194 | p[poll_server].events = POLLIN; |
195 | p[poll_server].revents = 0; | 195 | p[poll_server].revents = 0; |
196 | poll_listen = (int) poll_server; | 196 | poll_listen = (int) poll_server; |
197 | poll_server++; | 197 | poll_server++; |
198 | } | 198 | } |
199 | poll_itc_idx = -1; | 199 | poll_itc_idx = -1; |
200 | if (MHD_ITC_IS_VALID_(daemon->itc)) | 200 | if (MHD_ITC_IS_VALID_ (daemon->itc)) |
201 | { | 201 | { |
202 | p[poll_server].fd = MHD_itc_r_fd_ (daemon->itc); | 202 | p[poll_server].fd = MHD_itc_r_fd_ (daemon->itc); |
203 | p[poll_server].events = POLLIN; | 203 | p[poll_server].events = POLLIN; |
204 | p[poll_server].revents = 0; | 204 | p[poll_server].revents = 0; |
205 | poll_itc_idx = (int) poll_server; | 205 | poll_itc_idx = (int) poll_server; |
206 | poll_server++; | 206 | poll_server++; |
207 | } | 207 | } |
208 | if (! may_block) | 208 | if (! may_block) |
209 | timeout = 0; | 209 | timeout = 0; |
210 | else if ( (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode) || | 210 | else if ( (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode) || |
211 | (MHD_SC_OK != /* FIXME: distinguish between NO_TIMEOUT and errors! */ | 211 | (MHD_SC_OK != /* FIXME: distinguish between NO_TIMEOUT and errors! */ |
212 | MHD_daemon_get_timeout (daemon, | 212 | MHD_daemon_get_timeout (daemon, |
213 | <imeout)) ) | 213 | <imeout)) ) |
214 | timeout = -1; | 214 | timeout = -1; |
215 | else | 215 | else |
216 | timeout = (ltimeout > INT_MAX) ? INT_MAX : (int) ltimeout; | 216 | timeout = (ltimeout > INT_MAX) ? INT_MAX : (int) ltimeout; |
217 | 217 | ||
218 | i = 0; | 218 | i = 0; |
219 | for (pos = daemon->connections_tail; NULL != pos; pos = pos->prev) | 219 | for (pos = daemon->connections_tail; NULL != pos; pos = pos->prev) |
220 | { | ||
221 | p[poll_server + i].fd = pos->socket_fd; | ||
222 | switch (pos->request.event_loop_info) | ||
220 | { | 223 | { |
221 | p[poll_server+i].fd = pos->socket_fd; | 224 | case MHD_EVENT_LOOP_INFO_READ: |
222 | switch (pos->request.event_loop_info) | 225 | p[poll_server + i].events |= POLLIN | MHD_POLL_EVENTS_ERR_DISC; |
223 | { | 226 | break; |
224 | case MHD_EVENT_LOOP_INFO_READ: | 227 | case MHD_EVENT_LOOP_INFO_WRITE: |
225 | p[poll_server+i].events |= POLLIN | MHD_POLL_EVENTS_ERR_DISC; | 228 | p[poll_server + i].events |= POLLOUT | MHD_POLL_EVENTS_ERR_DISC; |
226 | break; | 229 | break; |
227 | case MHD_EVENT_LOOP_INFO_WRITE: | 230 | case MHD_EVENT_LOOP_INFO_BLOCK: |
228 | p[poll_server+i].events |= POLLOUT | MHD_POLL_EVENTS_ERR_DISC; | 231 | p[poll_server + i].events |= MHD_POLL_EVENTS_ERR_DISC; |
229 | break; | 232 | break; |
230 | case MHD_EVENT_LOOP_INFO_BLOCK: | 233 | case MHD_EVENT_LOOP_INFO_CLEANUP: |
231 | p[poll_server+i].events |= MHD_POLL_EVENTS_ERR_DISC; | 234 | timeout = 0; /* clean up "pos" immediately */ |
232 | break; | 235 | break; |
233 | case MHD_EVENT_LOOP_INFO_CLEANUP: | ||
234 | timeout = 0; /* clean up "pos" immediately */ | ||
235 | break; | ||
236 | } | ||
237 | i++; | ||
238 | } | 236 | } |
237 | i++; | ||
238 | } | ||
239 | #if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) | 239 | #if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) |
240 | for (urh = daemon->urh_tail; NULL != urh; urh = urh->prev) | 240 | for (urh = daemon->urh_tail; NULL != urh; urh = urh->prev) |
241 | { | 241 | { |
242 | urh_to_pollfd (urh, | 242 | urh_to_pollfd (urh, |
243 | &(p[poll_server+i])); | 243 | &(p[poll_server + i])); |
244 | i += 2; | 244 | i += 2; |
245 | } | 245 | } |
246 | #endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ | 246 | #endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ |
247 | if (0 == poll_server + num_connections) | 247 | if (0 == poll_server + num_connections) |
248 | { | ||
249 | free (p); | ||
250 | return MHD_SC_OK; | ||
251 | } | ||
252 | if (MHD_sys_poll_ (p, | ||
253 | poll_server + num_connections, | ||
254 | timeout) < 0) | ||
255 | { | ||
256 | const int err = MHD_socket_get_error_ (); | ||
257 | if (MHD_SCKT_ERR_IS_EINTR_ (err)) | ||
248 | { | 258 | { |
249 | free (p); | 259 | free (p); |
250 | return MHD_SC_OK; | 260 | return MHD_SC_OK; |
251 | } | 261 | } |
252 | if (MHD_sys_poll_(p, | ||
253 | poll_server + num_connections, | ||
254 | timeout) < 0) | ||
255 | { | ||
256 | const int err = MHD_socket_get_error_ (); | ||
257 | if (MHD_SCKT_ERR_IS_EINTR_ (err)) | ||
258 | { | ||
259 | free(p); | ||
260 | return MHD_SC_OK; | ||
261 | } | ||
262 | #ifdef HAVE_MESSAGES | 262 | #ifdef HAVE_MESSAGES |
263 | MHD_DLOG (daemon, | 263 | MHD_DLOG (daemon, |
264 | MHD_SC_UNEXPECTED_POLL_ERROR, | 264 | MHD_SC_UNEXPECTED_POLL_ERROR, |
265 | _("poll failed: %s\n"), | 265 | _ ("poll failed: %s\n"), |
266 | MHD_socket_strerr_ (err)); | 266 | MHD_socket_strerr_ (err)); |
267 | #endif | 267 | #endif |
268 | free(p); | 268 | free (p); |
269 | return MHD_SC_UNEXPECTED_POLL_ERROR; | 269 | return MHD_SC_UNEXPECTED_POLL_ERROR; |
270 | } | 270 | } |
271 | 271 | ||
272 | /* Reset. New value will be set when connections are processed. */ | 272 | /* Reset. New value will be set when connections are processed. */ |
273 | daemon->data_already_pending = false; | 273 | daemon->data_already_pending = false; |
@@ -281,67 +281,69 @@ MHD_daemon_poll_all_ (struct MHD_Daemon *daemon, | |||
281 | 281 | ||
282 | /* handle shutdown */ | 282 | /* handle shutdown */ |
283 | if (daemon->shutdown) | 283 | if (daemon->shutdown) |
284 | { | 284 | { |
285 | free(p); | 285 | free (p); |
286 | return MHD_SC_DAEMON_ALREADY_SHUTDOWN; | 286 | return MHD_SC_DAEMON_ALREADY_SHUTDOWN; |
287 | } | 287 | } |
288 | i = 0; | 288 | i = 0; |
289 | prev = daemon->connections_tail; | 289 | prev = daemon->connections_tail; |
290 | while (NULL != (pos = prev)) | 290 | while (NULL != (pos = prev)) |
291 | { | 291 | { |
292 | prev = pos->prev; | 292 | prev = pos->prev; |
293 | /* first, sanity checks */ | 293 | /* first, sanity checks */ |
294 | if (i >= num_connections) | 294 | if (i >= num_connections) |
295 | break; /* connection list changed somehow, retry later ... */ | 295 | break; /* connection list changed somehow, retry later ... */ |
296 | if (p[poll_server+i].fd != pos->socket_fd) | 296 | if (p[poll_server + i].fd != pos->socket_fd) |
297 | continue; /* fd mismatch, something else happened, retry later ... */ | 297 | continue; /* fd mismatch, something else happened, retry later ... */ |
298 | MHD_connection_call_handlers_ (pos, | 298 | MHD_connection_call_handlers_ (pos, |
299 | 0 != (p[poll_server+i].revents & POLLIN), | 299 | 0 != (p[poll_server + i].revents & POLLIN), |
300 | 0 != (p[poll_server+i].revents & POLLOUT), | 300 | 0 != (p[poll_server + i].revents |
301 | 0 != (p[poll_server+i].revents & MHD_POLL_REVENTS_ERR_DISC)); | 301 | & POLLOUT), |
302 | i++; | 302 | 0 != (p[poll_server + i].revents |
303 | } | 303 | & MHD_POLL_REVENTS_ERR_DISC)); |
304 | i++; | ||
305 | } | ||
304 | #if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) | 306 | #if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) |
305 | for (urh = daemon->urh_tail; NULL != urh; urh = urhn) | 307 | for (urh = daemon->urh_tail; NULL != urh; urh = urhn) |
308 | { | ||
309 | if (i >= num_connections) | ||
310 | break; /* connection list changed somehow, retry later ... */ | ||
311 | |||
312 | /* Get next connection here as connection can be removed | ||
313 | * from 'daemon->urh_head' list. */ | ||
314 | urhn = urh->prev; | ||
315 | /* Check for fd mismatch. FIXME: required for safety? */ | ||
316 | if ((p[poll_server + i].fd != urh->connection->socket_fd) || | ||
317 | (p[poll_server + i + 1].fd != urh->mhd.socket)) | ||
318 | break; | ||
319 | urh_from_pollfd (urh, | ||
320 | &p[poll_server + i]); | ||
321 | i += 2; | ||
322 | MHD_upgrade_response_handle_process_ (urh); | ||
323 | /* Finished forwarding? */ | ||
324 | if ( (0 == urh->in_buffer_size) && | ||
325 | (0 == urh->out_buffer_size) && | ||
326 | (0 == urh->in_buffer_used) && | ||
327 | (0 == urh->out_buffer_used) ) | ||
306 | { | 328 | { |
307 | if (i >= num_connections) | 329 | /* MHD_connection_finish_forward_() will remove connection from |
308 | break; /* connection list changed somehow, retry later ... */ | 330 | * 'daemon->urh_head' list. */ |
309 | 331 | MHD_connection_finish_forward_ (urh->connection); | |
310 | /* Get next connection here as connection can be removed | 332 | urh->clean_ready = true; |
311 | * from 'daemon->urh_head' list. */ | 333 | /* If 'urh->was_closed' already was set to true, connection will be |
312 | urhn = urh->prev; | 334 | * moved immediately to cleanup list. Otherwise connection |
313 | /* Check for fd mismatch. FIXME: required for safety? */ | 335 | * will stay in suspended list until 'urh' will be marked |
314 | if ((p[poll_server+i].fd != urh->connection->socket_fd) || | 336 | * with 'was_closed' by application. */ |
315 | (p[poll_server+i+1].fd != urh->mhd.socket)) | 337 | MHD_request_resume (&urh->connection->request); |
316 | break; | ||
317 | urh_from_pollfd (urh, | ||
318 | &p[poll_server+i]); | ||
319 | i += 2; | ||
320 | MHD_upgrade_response_handle_process_ (urh); | ||
321 | /* Finished forwarding? */ | ||
322 | if ( (0 == urh->in_buffer_size) && | ||
323 | (0 == urh->out_buffer_size) && | ||
324 | (0 == urh->in_buffer_used) && | ||
325 | (0 == urh->out_buffer_used) ) | ||
326 | { | ||
327 | /* MHD_connection_finish_forward_() will remove connection from | ||
328 | * 'daemon->urh_head' list. */ | ||
329 | MHD_connection_finish_forward_ (urh->connection); | ||
330 | urh->clean_ready = true; | ||
331 | /* If 'urh->was_closed' already was set to true, connection will be | ||
332 | * moved immediately to cleanup list. Otherwise connection | ||
333 | * will stay in suspended list until 'urh' will be marked | ||
334 | * with 'was_closed' by application. */ | ||
335 | MHD_request_resume (&urh->connection->request); | ||
336 | } | ||
337 | } | 338 | } |
339 | } | ||
338 | #endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ | 340 | #endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ |
339 | /* handle 'listen' FD */ | 341 | /* handle 'listen' FD */ |
340 | if ( (-1 != poll_listen) && | 342 | if ( (-1 != poll_listen) && |
341 | (0 != (p[poll_listen].revents & POLLIN)) ) | 343 | (0 != (p[poll_listen].revents & POLLIN)) ) |
342 | (void) MHD_accept_connection_ (daemon); | 344 | (void) MHD_accept_connection_ (daemon); |
343 | 345 | ||
344 | free(p); | 346 | free (p); |
345 | } | 347 | } |
346 | return MHD_SC_OK; | 348 | return MHD_SC_OK; |
347 | } | 349 | } |
@@ -356,7 +358,7 @@ MHD_daemon_poll_all_ (struct MHD_Daemon *daemon, | |||
356 | */ | 358 | */ |
357 | enum MHD_StatusCode | 359 | enum MHD_StatusCode |
358 | MHD_daemon_poll_listen_socket_ (struct MHD_Daemon *daemon, | 360 | MHD_daemon_poll_listen_socket_ (struct MHD_Daemon *daemon, |
359 | bool may_block) | 361 | bool may_block) |
360 | { | 362 | { |
361 | struct pollfd p[2]; | 363 | struct pollfd p[2]; |
362 | int timeout; | 364 | int timeout; |
@@ -374,21 +376,21 @@ MHD_daemon_poll_listen_socket_ (struct MHD_Daemon *daemon, | |||
374 | if ( (MHD_INVALID_SOCKET != (ls = daemon->listen_socket)) && | 376 | if ( (MHD_INVALID_SOCKET != (ls = daemon->listen_socket)) && |
375 | (! daemon->was_quiesced) ) | 377 | (! daemon->was_quiesced) ) |
376 | 378 | ||
377 | { | 379 | { |
378 | p[poll_count].fd = ls; | 380 | p[poll_count].fd = ls; |
379 | p[poll_count].events = POLLIN; | 381 | p[poll_count].events = POLLIN; |
380 | p[poll_count].revents = 0; | 382 | p[poll_count].revents = 0; |
381 | poll_listen = poll_count; | 383 | poll_listen = poll_count; |
382 | poll_count++; | 384 | poll_count++; |
383 | } | 385 | } |
384 | if (MHD_ITC_IS_VALID_(daemon->itc)) | 386 | if (MHD_ITC_IS_VALID_ (daemon->itc)) |
385 | { | 387 | { |
386 | p[poll_count].fd = MHD_itc_r_fd_ (daemon->itc); | 388 | p[poll_count].fd = MHD_itc_r_fd_ (daemon->itc); |
387 | p[poll_count].events = POLLIN; | 389 | p[poll_count].events = POLLIN; |
388 | p[poll_count].revents = 0; | 390 | p[poll_count].revents = 0; |
389 | poll_itc_idx = poll_count; | 391 | poll_itc_idx = poll_count; |
390 | poll_count++; | 392 | poll_count++; |
391 | } | 393 | } |
392 | 394 | ||
393 | if (! daemon->disallow_suspend_resume) | 395 | if (! daemon->disallow_suspend_resume) |
394 | (void) MHD_resume_suspended_connections_ (daemon); | 396 | (void) MHD_resume_suspended_connections_ (daemon); |
@@ -399,22 +401,22 @@ MHD_daemon_poll_listen_socket_ (struct MHD_Daemon *daemon, | |||
399 | timeout = -1; | 401 | timeout = -1; |
400 | if (0 == poll_count) | 402 | if (0 == poll_count) |
401 | return MHD_SC_OK; | 403 | return MHD_SC_OK; |
402 | if (MHD_sys_poll_(p, | 404 | if (MHD_sys_poll_ (p, |
403 | poll_count, | 405 | poll_count, |
404 | timeout) < 0) | 406 | timeout) < 0) |
405 | { | 407 | { |
406 | const int err = MHD_socket_get_error_ (); | 408 | const int err = MHD_socket_get_error_ (); |
407 | 409 | ||
408 | if (MHD_SCKT_ERR_IS_EINTR_ (err)) | 410 | if (MHD_SCKT_ERR_IS_EINTR_ (err)) |
409 | return MHD_SC_OK; | 411 | return MHD_SC_OK; |
410 | #ifdef HAVE_MESSAGES | 412 | #ifdef HAVE_MESSAGES |
411 | MHD_DLOG (daemon, | 413 | MHD_DLOG (daemon, |
412 | MHD_SC_UNEXPECTED_POLL_ERROR, | 414 | MHD_SC_UNEXPECTED_POLL_ERROR, |
413 | _("poll failed: %s\n"), | 415 | _ ("poll failed: %s\n"), |
414 | MHD_socket_strerr_ (err)); | 416 | MHD_socket_strerr_ (err)); |
415 | #endif | 417 | #endif |
416 | return MHD_SC_UNEXPECTED_POLL_ERROR; | 418 | return MHD_SC_UNEXPECTED_POLL_ERROR; |
417 | } | 419 | } |
418 | if ( (-1 != poll_itc_idx) && | 420 | if ( (-1 != poll_itc_idx) && |
419 | (0 != (p[poll_itc_idx].revents & POLLIN)) ) | 421 | (0 != (p[poll_itc_idx].revents & POLLIN)) ) |
420 | MHD_itc_clear_ (daemon->itc); | 422 | MHD_itc_clear_ (daemon->itc); |
@@ -439,16 +441,16 @@ MHD_daemon_poll_listen_socket_ (struct MHD_Daemon *daemon, | |||
439 | */ | 441 | */ |
440 | enum MHD_StatusCode | 442 | enum MHD_StatusCode |
441 | MHD_daemon_poll_ (struct MHD_Daemon *daemon, | 443 | MHD_daemon_poll_ (struct MHD_Daemon *daemon, |
442 | bool may_block) | 444 | bool may_block) |
443 | { | 445 | { |
444 | #ifdef HAVE_POLL | 446 | #ifdef HAVE_POLL |
445 | if (daemon->shutdown) | 447 | if (daemon->shutdown) |
446 | return MHD_SC_DAEMON_ALREADY_SHUTDOWN; | 448 | return MHD_SC_DAEMON_ALREADY_SHUTDOWN; |
447 | if (MHD_TM_THREAD_PER_CONNECTION != daemon->threading_mode) | 449 | if (MHD_TM_THREAD_PER_CONNECTION != daemon->threading_mode) |
448 | return MHD_daemon_poll_all_ (daemon, | 450 | return MHD_daemon_poll_all_ (daemon, |
449 | may_block); | 451 | may_block); |
450 | return MHD_daemon_poll_listen_socket_ (daemon, | 452 | return MHD_daemon_poll_listen_socket_ (daemon, |
451 | may_block); | 453 | may_block); |
452 | #else | 454 | #else |
453 | /* This code should be dead, as we should have checked | 455 | /* This code should be dead, as we should have checked |
454 | this earlier... */ | 456 | this earlier... */ |
@@ -472,47 +474,47 @@ MHD_daemon_upgrade_connection_with_poll_ (struct MHD_Connection *con) | |||
472 | struct pollfd p[2]; | 474 | struct pollfd p[2]; |
473 | 475 | ||
474 | memset (p, | 476 | memset (p, |
475 | 0, | 477 | 0, |
476 | sizeof (p)); | 478 | sizeof (p)); |
477 | p[0].fd = urh->connection->socket_fd; | 479 | p[0].fd = urh->connection->socket_fd; |
478 | p[1].fd = urh->mhd.socket; | 480 | p[1].fd = urh->mhd.socket; |
479 | 481 | ||
480 | while ( (0 != urh->in_buffer_size) || | 482 | while ( (0 != urh->in_buffer_size) || |
481 | (0 != urh->out_buffer_size) || | 483 | (0 != urh->out_buffer_size) || |
482 | (0 != urh->in_buffer_used) || | 484 | (0 != urh->in_buffer_used) || |
483 | (0 != urh->out_buffer_used) ) | 485 | (0 != urh->out_buffer_used) ) |
484 | { | 486 | { |
485 | int timeout; | 487 | int timeout; |
486 | 488 | ||
487 | urh_update_pollfd (urh, | 489 | urh_update_pollfd (urh, |
488 | p); | 490 | p); |
489 | 491 | ||
490 | if ( (con->tls_read_ready) && | 492 | if ( (con->tls_read_ready) && |
491 | (urh->in_buffer_used < urh->in_buffer_size)) | 493 | (urh->in_buffer_used < urh->in_buffer_size)) |
492 | timeout = 0; /* No need to wait if incoming data is already pending in TLS buffers. */ | 494 | timeout = 0; /* No need to wait if incoming data is already pending in TLS buffers. */ |
493 | else | 495 | else |
494 | timeout = -1; | 496 | timeout = -1; |
495 | 497 | ||
496 | if (MHD_sys_poll_ (p, | 498 | if (MHD_sys_poll_ (p, |
497 | 2, | 499 | 2, |
498 | timeout) < 0) | 500 | timeout) < 0) |
499 | { | 501 | { |
500 | const int err = MHD_socket_get_error_ (); | 502 | const int err = MHD_socket_get_error_ (); |
501 | 503 | ||
502 | if (MHD_SCKT_ERR_IS_EINTR_ (err)) | 504 | if (MHD_SCKT_ERR_IS_EINTR_ (err)) |
503 | continue; | 505 | continue; |
504 | #ifdef HAVE_MESSAGES | 506 | #ifdef HAVE_MESSAGES |
505 | MHD_DLOG (con->daemon, | 507 | MHD_DLOG (con->daemon, |
506 | MHD_SC_UNEXPECTED_POLL_ERROR, | 508 | MHD_SC_UNEXPECTED_POLL_ERROR, |
507 | _("Error during poll: `%s'\n"), | 509 | _ ("Error during poll: `%s'\n"), |
508 | MHD_socket_strerr_ (err)); | 510 | MHD_socket_strerr_ (err)); |
509 | #endif | 511 | #endif |
510 | break; | 512 | break; |
511 | } | ||
512 | urh_from_pollfd (urh, | ||
513 | p); | ||
514 | MHD_upgrade_response_handle_process_ (urh); | ||
515 | } | 513 | } |
514 | urh_from_pollfd (urh, | ||
515 | p); | ||
516 | MHD_upgrade_response_handle_process_ (urh); | ||
517 | } | ||
516 | } | 518 | } |
517 | #endif | 519 | #endif |
518 | #endif | 520 | #endif |