diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-09-22 14:33:39 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-09-22 14:33:39 +0000 |
commit | 9c1254792ca4971b36d06706e9d51c253d96106d (patch) | |
tree | ea785c930b48f073e51c9c8a119d43081f42a3e5 /src/microhttpd/daemon.c | |
parent | df6d586ac2f0f73bcd817638a1100bf5972faca9 (diff) | |
download | libmicrohttpd-9c1254792ca4971b36d06706e9d51c253d96106d.tar.gz libmicrohttpd-9c1254792ca4971b36d06706e9d51c253d96106d.zip |
raising MHD_Pipe API abstraction level in preparation for fixing #3557
Diffstat (limited to 'src/microhttpd/daemon.c')
-rw-r--r-- | src/microhttpd/daemon.c | 161 |
1 files changed, 61 insertions, 100 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c index cfaf2e1c..239a19ea 100644 --- a/src/microhttpd/daemon.c +++ b/src/microhttpd/daemon.c | |||
@@ -1276,7 +1276,6 @@ thread_main_handle_connection (void *data) | |||
1276 | struct timeval *tvp; | 1276 | struct timeval *tvp; |
1277 | time_t now; | 1277 | time_t now; |
1278 | #if WINDOWS | 1278 | #if WINDOWS |
1279 | MHD_pipe spipe = daemon->wpipe[0]; | ||
1280 | #ifdef HAVE_POLL | 1279 | #ifdef HAVE_POLL |
1281 | int extra_slot; | 1280 | int extra_slot; |
1282 | #endif /* HAVE_POLL */ | 1281 | #endif /* HAVE_POLL */ |
@@ -1371,9 +1370,9 @@ thread_main_handle_connection (void *data) | |||
1371 | goto exit; | 1370 | goto exit; |
1372 | } | 1371 | } |
1373 | #if WINDOWS | 1372 | #if WINDOWS |
1374 | if (MHD_INVALID_PIPE_ != spipe) | 1373 | if (! MHD_INVALID_PIPE_(deamon->wpipe) ) |
1375 | { | 1374 | { |
1376 | if (! MHD_add_to_fd_set_ (spipe, | 1375 | if (! MHD_add_to_fd_set_ (MHD_pipe_get_read_fd_ (daemon->wpipe), |
1377 | &rs, | 1376 | &rs, |
1378 | &maxsock, | 1377 | &maxsock, |
1379 | FD_SETSIZE)) | 1378 | FD_SETSIZE)) |
@@ -1410,10 +1409,10 @@ thread_main_handle_connection (void *data) | |||
1410 | } | 1409 | } |
1411 | #if WINDOWS | 1410 | #if WINDOWS |
1412 | /* drain signaling pipe before other processing */ | 1411 | /* drain signaling pipe before other processing */ |
1413 | if ( (MHD_INVALID_PIPE_ != spipe) && | 1412 | if ( (! MHD_INVALID_PIPE_(daemon->wpipe)) && |
1414 | (FD_ISSET (spipe, | 1413 | (FD_ISSET (MHD_pipe_get_read_fd_ (daemon->wpipe), |
1415 | &rs)) ) | 1414 | &rs)) ) |
1416 | MHD_pipe_drain_ (spipe); | 1415 | MHD_pipe_drain_ (daemon->wpipe); |
1417 | #endif | 1416 | #endif |
1418 | if (MHD_NO == | 1417 | if (MHD_NO == |
1419 | call_handlers (con, | 1418 | call_handlers (con, |
@@ -1455,10 +1454,10 @@ thread_main_handle_connection (void *data) | |||
1455 | } | 1454 | } |
1456 | #if WINDOWS | 1455 | #if WINDOWS |
1457 | extra_slot = 0; | 1456 | extra_slot = 0; |
1458 | if (MHD_INVALID_PIPE_ != spipe) | 1457 | if (! MHD_INVALID_PIPE_(daemon->wpipe)) |
1459 | { | 1458 | { |
1460 | p[1].events |= POLLIN; | 1459 | p[1].events |= POLLIN; |
1461 | p[1].fd = spipe; | 1460 | p[1].fd = MHD_pipe_get_read_fd_ (daemon->wpipe); |
1462 | p[1].revents = 0; | 1461 | p[1].revents = 0; |
1463 | extra_slot = 1; | 1462 | extra_slot = 1; |
1464 | } | 1463 | } |
@@ -1482,9 +1481,9 @@ thread_main_handle_connection (void *data) | |||
1482 | } | 1481 | } |
1483 | #if WINDOWS | 1482 | #if WINDOWS |
1484 | /* drain signaling pipe before other processing */ | 1483 | /* drain signaling pipe before other processing */ |
1485 | if ( (MHD_INVALID_PIPE_ != spipe) && | 1484 | if ( (! MHD_INVALID_PIPE_(daemon->wpipe)) && |
1486 | (0 != (p[1].revents & (POLLERR | POLLHUP | POLLIN))) ) | 1485 | (0 != (p[1].revents & (POLLERR | POLLHUP | POLLIN))) ) |
1487 | MHD_pipe_drain_ (spipe); | 1486 | MHD_pipe_drain_ (daemon->wpipe); |
1488 | #endif | 1487 | #endif |
1489 | if (MHD_NO == | 1488 | if (MHD_NO == |
1490 | call_handlers (con, | 1489 | call_handlers (con, |
@@ -2025,8 +2024,8 @@ internal_add_connection (struct MHD_Daemon *daemon, | |||
2025 | } | 2024 | } |
2026 | else | 2025 | else |
2027 | if ( (MHD_YES == external_add) && | 2026 | if ( (MHD_YES == external_add) && |
2028 | (MHD_INVALID_PIPE_ != daemon->wpipe[1]) && | 2027 | (! MHD_INVALID_PIPE_(daemon->wpipe)) && |
2029 | (1 != MHD_pipe_write_ (daemon->wpipe[1], | 2028 | (1 != MHD_pipe_write_ (daemon->wpipe, |
2030 | "n", | 2029 | "n", |
2031 | 1)) ) | 2030 | 1)) ) |
2032 | { | 2031 | { |
@@ -2208,8 +2207,8 @@ MHD_resume_connection (struct MHD_Connection *connection) | |||
2208 | MHD_mutex_lock_ (&daemon->cleanup_connection_mutex); | 2207 | MHD_mutex_lock_ (&daemon->cleanup_connection_mutex); |
2209 | connection->resuming = MHD_YES; | 2208 | connection->resuming = MHD_YES; |
2210 | daemon->resuming = MHD_YES; | 2209 | daemon->resuming = MHD_YES; |
2211 | if ( (MHD_INVALID_PIPE_ != daemon->wpipe[1]) && | 2210 | if ( (! MHD_INVALID_PIPE_(daemon->wpipe)) && |
2212 | (1 != MHD_pipe_write_ (daemon->wpipe[1], "r", 1)) ) | 2211 | (1 != MHD_pipe_write_ (daemon->wpipe, "r", 1)) ) |
2213 | { | 2212 | { |
2214 | #ifdef HAVE_MESSAGES | 2213 | #ifdef HAVE_MESSAGES |
2215 | MHD_DLOG (daemon, | 2214 | MHD_DLOG (daemon, |
@@ -2703,10 +2702,10 @@ MHD_run_from_select (struct MHD_Daemon *daemon, | |||
2703 | /* drain signaling pipe to avoid spinning select */ | 2702 | /* drain signaling pipe to avoid spinning select */ |
2704 | /* Do it before any other processing so new signals | 2703 | /* Do it before any other processing so new signals |
2705 | will trigger select again and will be processed */ | 2704 | will trigger select again and will be processed */ |
2706 | if ((MHD_INVALID_PIPE_ != daemon->wpipe[0]) && | 2705 | if ( (! MHD_INVALID_PIPE_(daemon->wpipe)) && |
2707 | (FD_ISSET (daemon->wpipe[0], | 2706 | (FD_ISSET (MHD_pipe_get_read_fd_ (daemon->wpipe), |
2708 | read_fd_set))) | 2707 | read_fd_set)) ) |
2709 | MHD_pipe_drain_ (daemon->wpipe[0]); | 2708 | MHD_pipe_drain_ (daemon->wpipe); |
2710 | 2709 | ||
2711 | /* Resuming external connections when using an extern mainloop */ | 2710 | /* Resuming external connections when using an extern mainloop */ |
2712 | if (MHD_USE_SUSPEND_RESUME == (daemon->options & mask)) | 2711 | if (MHD_USE_SUSPEND_RESUME == (daemon->options & mask)) |
@@ -2839,8 +2838,8 @@ MHD_select (struct MHD_Daemon *daemon, | |||
2839 | return MHD_NO; | 2838 | return MHD_NO; |
2840 | } | 2839 | } |
2841 | } | 2840 | } |
2842 | if ( (MHD_INVALID_PIPE_ != daemon->wpipe[0]) && | 2841 | if ( (! MHD_INVALID_PIPE_(daemon->wpipe)) && |
2843 | (! MHD_add_to_fd_set_ (daemon->wpipe[0], | 2842 | (! MHD_add_to_fd_set_ (MHD_pipe_get_read_fd_ (daemon->wpipe), |
2844 | &rs, | 2843 | &rs, |
2845 | &maxsock, | 2844 | &maxsock, |
2846 | FD_SETSIZE)) ) | 2845 | FD_SETSIZE)) ) |
@@ -2876,7 +2875,7 @@ MHD_select (struct MHD_Daemon *daemon, | |||
2876 | only do this optimization if we have a signaling pipe in | 2875 | only do this optimization if we have a signaling pipe in |
2877 | place. */ | 2876 | place. */ |
2878 | if ( (MHD_INVALID_SOCKET != daemon->socket_fd) && | 2877 | if ( (MHD_INVALID_SOCKET != daemon->socket_fd) && |
2879 | (MHD_INVALID_PIPE_ != daemon->wpipe[0]) && | 2878 | (! MHD_INVALID_PIPE_(daemon->wpipe)) && |
2880 | (0 != (daemon->options & MHD_USE_PIPE_FOR_SHUTDOWN)) && | 2879 | (0 != (daemon->options & MHD_USE_PIPE_FOR_SHUTDOWN)) && |
2881 | ( (daemon->connections == daemon->connection_limit) || | 2880 | ( (daemon->connections == daemon->connection_limit) || |
2882 | (MHD_YES == daemon->at_limit) ) ) | 2881 | (MHD_YES == daemon->at_limit) ) ) |
@@ -3001,9 +3000,9 @@ MHD_poll_all (struct MHD_Daemon *daemon, | |||
3001 | poll_server++; | 3000 | poll_server++; |
3002 | } | 3001 | } |
3003 | poll_pipe = -1; | 3002 | poll_pipe = -1; |
3004 | if (MHD_INVALID_PIPE_ != daemon->wpipe[0]) | 3003 | if (! MHD_INVALID_PIPE_(daemon->wpipe)) |
3005 | { | 3004 | { |
3006 | p[poll_server].fd = daemon->wpipe[0]; | 3005 | p[poll_server].fd = MHD_pipe_get_read_fd_ (daemon->wpipe); |
3007 | p[poll_server].events = POLLIN; | 3006 | p[poll_server].events = POLLIN; |
3008 | p[poll_server].revents = 0; | 3007 | p[poll_server].revents = 0; |
3009 | poll_pipe = (int) poll_server; | 3008 | poll_pipe = (int) poll_server; |
@@ -3087,7 +3086,7 @@ MHD_poll_all (struct MHD_Daemon *daemon, | |||
3087 | new signals will be processed in next loop */ | 3086 | new signals will be processed in next loop */ |
3088 | if ( (-1 != poll_pipe) && | 3087 | if ( (-1 != poll_pipe) && |
3089 | (0 != (p[poll_pipe].revents & POLLIN)) ) | 3088 | (0 != (p[poll_pipe].revents & POLLIN)) ) |
3090 | MHD_pipe_drain_ (daemon->wpipe[0]); | 3089 | MHD_pipe_drain_ (daemon->wpipe); |
3091 | 3090 | ||
3092 | /* handle shutdown */ | 3091 | /* handle shutdown */ |
3093 | if (MHD_YES == daemon->shutdown) | 3092 | if (MHD_YES == daemon->shutdown) |
@@ -3182,9 +3181,9 @@ MHD_poll_listen_socket (struct MHD_Daemon *daemon, | |||
3182 | poll_listen = poll_count; | 3181 | poll_listen = poll_count; |
3183 | poll_count++; | 3182 | poll_count++; |
3184 | } | 3183 | } |
3185 | if (MHD_INVALID_PIPE_ != daemon->wpipe[0]) | 3184 | if (! MHD_INVALID_PIPE_(daemon->wpipe)) |
3186 | { | 3185 | { |
3187 | p[poll_count].fd = daemon->wpipe[0]; | 3186 | p[poll_count].fd = MHD_pipe_get_read_fd_ (daemon->wpipe); |
3188 | p[poll_count].events = POLLIN; | 3187 | p[poll_count].events = POLLIN; |
3189 | p[poll_count].revents = 0; | 3188 | p[poll_count].revents = 0; |
3190 | poll_pipe = poll_count; | 3189 | poll_pipe = poll_count; |
@@ -3213,7 +3212,7 @@ MHD_poll_listen_socket (struct MHD_Daemon *daemon, | |||
3213 | } | 3212 | } |
3214 | if ( (-1 != poll_pipe) && | 3213 | if ( (-1 != poll_pipe) && |
3215 | (0 != (p[poll_pipe].revents & POLLIN)) ) | 3214 | (0 != (p[poll_pipe].revents & POLLIN)) ) |
3216 | MHD_pipe_drain_ (daemon->wpipe[0]); | 3215 | MHD_pipe_drain_ (daemon->wpipe); |
3217 | 3216 | ||
3218 | /* handle shutdown */ | 3217 | /* handle shutdown */ |
3219 | if (MHD_YES == daemon->shutdown) | 3218 | if (MHD_YES == daemon->shutdown) |
@@ -3488,15 +3487,15 @@ MHD_epoll (struct MHD_Daemon *daemon, | |||
3488 | #endif | 3487 | #endif |
3489 | /* UGH: we're storing pointers and fds in the same union | 3488 | /* UGH: we're storing pointers and fds in the same union |
3490 | here; incredibly ugly and somewhat risky, even though a | 3489 | here; incredibly ugly and somewhat risky, even though a |
3491 | pointer with the same numeric value as the wpipe[0] can | 3490 | pointer with the same numeric value as the wpipe.fd[0] can |
3492 | be expected to be rare... FIXME (a construction similar | 3491 | be expected to be rare... FIXME (a construction similar |
3493 | to what we did with the `upgrade_marker` should do) */ | 3492 | to what we did with the `upgrade_marker` should do) */ |
3494 | if ( (MHD_INVALID_PIPE_ != daemon->wpipe[0]) && | 3493 | if ( (! MHD_INVALID_PIPE_(daemon->wpipe)) && |
3495 | (daemon->wpipe[0] == events[i].data.fd) ) | 3494 | (MHD_pipe_get_read_fd_ (daemon->wpipe) == events[i].data.fd) ) |
3496 | { | 3495 | { |
3497 | /* It's OK to drain pipe here as all external | 3496 | /* It's OK to drain pipe here as all external |
3498 | conditions will be processed later. */ | 3497 | conditions will be processed later. */ |
3499 | MHD_pipe_drain_ (daemon->wpipe[0]); | 3498 | MHD_pipe_drain_ (daemon->wpipe); |
3500 | continue; | 3499 | continue; |
3501 | } | 3500 | } |
3502 | if (daemon == events[i].data.ptr) | 3501 | if (daemon == events[i].data.ptr) |
@@ -3759,7 +3758,7 @@ MHD_quiesce_daemon (struct MHD_Daemon *daemon) | |||
3759 | ret = daemon->socket_fd; | 3758 | ret = daemon->socket_fd; |
3760 | if (MHD_INVALID_SOCKET == ret) | 3759 | if (MHD_INVALID_SOCKET == ret) |
3761 | return MHD_INVALID_SOCKET; | 3760 | return MHD_INVALID_SOCKET; |
3762 | if ( (MHD_INVALID_PIPE_ == daemon->wpipe[1]) && | 3761 | if ( (MHD_INVALID_PIPE_(daemon->wpipe)) && |
3763 | (0 != (daemon->options & (MHD_USE_SELECT_INTERNALLY | MHD_USE_THREAD_PER_CONNECTION))) ) | 3762 | (0 != (daemon->options & (MHD_USE_SELECT_INTERNALLY | MHD_USE_THREAD_PER_CONNECTION))) ) |
3764 | { | 3763 | { |
3765 | #ifdef HAVE_MESSAGES | 3764 | #ifdef HAVE_MESSAGES |
@@ -3787,9 +3786,9 @@ MHD_quiesce_daemon (struct MHD_Daemon *daemon) | |||
3787 | } | 3786 | } |
3788 | else | 3787 | else |
3789 | #endif | 3788 | #endif |
3790 | if (MHD_INVALID_PIPE_ != daemon->worker_pool[i].wpipe[1]) | 3789 | if (! MHD_INVALID_PIPE_(daemon->worker_pool[i].wpipe)) |
3791 | { | 3790 | { |
3792 | if (1 != MHD_pipe_write_ (daemon->worker_pool[i].wpipe[1], | 3791 | if (1 != MHD_pipe_write_ (daemon->worker_pool[i].wpipe, |
3793 | "q", | 3792 | "q", |
3794 | 1)) | 3793 | 1)) |
3795 | MHD_PANIC (_("Failed to signal quiesce via pipe")); | 3794 | MHD_PANIC (_("Failed to signal quiesce via pipe")); |
@@ -3810,9 +3809,9 @@ MHD_quiesce_daemon (struct MHD_Daemon *daemon) | |||
3810 | } | 3809 | } |
3811 | else | 3810 | else |
3812 | #endif | 3811 | #endif |
3813 | if (MHD_INVALID_PIPE_ != daemon->wpipe[1]) | 3812 | if (! MHD_INVALID_PIPE_(daemon->wpipe)) |
3814 | { | 3813 | { |
3815 | if (1 != MHD_pipe_write_ (daemon->wpipe[1], | 3814 | if (1 != MHD_pipe_write_ (daemon->wpipe, |
3816 | "q", | 3815 | "q", |
3817 | 1)) | 3816 | 1)) |
3818 | MHD_PANIC (_("failed to signal quiesce via pipe")); | 3817 | MHD_PANIC (_("failed to signal quiesce via pipe")); |
@@ -4325,15 +4324,15 @@ setup_epoll_to_listen (struct MHD_Daemon *daemon) | |||
4325 | #endif | 4324 | #endif |
4326 | return MHD_NO; | 4325 | return MHD_NO; |
4327 | } | 4326 | } |
4328 | if ( (MHD_INVALID_PIPE_ != daemon->wpipe[0]) && | 4327 | if ( (! MHD_INVALID_PIPE_(daemon->wpipe)) && |
4329 | (MHD_USE_SUSPEND_RESUME == (daemon->options & MHD_USE_SUSPEND_RESUME)) ) | 4328 | (MHD_USE_SUSPEND_RESUME == (daemon->options & MHD_USE_SUSPEND_RESUME)) ) |
4330 | { | 4329 | { |
4331 | event.events = EPOLLIN | EPOLLET; | 4330 | event.events = EPOLLIN | EPOLLET; |
4332 | event.data.ptr = NULL; | 4331 | event.data.ptr = NULL; |
4333 | event.data.fd = daemon->wpipe[0]; | 4332 | event.data.fd = MHD_pipe_get_read_fd_ (daemon->wpipe); |
4334 | if (0 != epoll_ctl (daemon->epoll_fd, | 4333 | if (0 != epoll_ctl (daemon->epoll_fd, |
4335 | EPOLL_CTL_ADD, | 4334 | EPOLL_CTL_ADD, |
4336 | daemon->wpipe[0], | 4335 | MHD_pipe_get_read_fd_ (daemon->wpipe), |
4337 | &event)) | 4336 | &event)) |
4338 | { | 4337 | { |
4339 | #ifdef HAVE_MESSAGES | 4338 | #ifdef HAVE_MESSAGES |
@@ -4440,8 +4439,7 @@ MHD_start_daemon_va (unsigned int flags, | |||
4440 | daemon->pool_increment = MHD_BUF_INC_SIZE; | 4439 | daemon->pool_increment = MHD_BUF_INC_SIZE; |
4441 | daemon->unescape_callback = &unescape_wrapper; | 4440 | daemon->unescape_callback = &unescape_wrapper; |
4442 | daemon->connection_timeout = 0; /* no timeout */ | 4441 | daemon->connection_timeout = 0; /* no timeout */ |
4443 | daemon->wpipe[0] = MHD_INVALID_PIPE_; | 4442 | MHD_make_invalid_pipe_ (daemon->wpipe); |
4444 | daemon->wpipe[1] = MHD_INVALID_PIPE_; | ||
4445 | #ifdef SOMAXCONN | 4443 | #ifdef SOMAXCONN |
4446 | daemon->listen_backlog_size = SOMAXCONN; | 4444 | daemon->listen_backlog_size = SOMAXCONN; |
4447 | #else /* !SOMAXCONN */ | 4445 | #else /* !SOMAXCONN */ |
@@ -4470,42 +4468,28 @@ MHD_start_daemon_va (unsigned int flags, | |||
4470 | free (daemon); | 4468 | free (daemon); |
4471 | return NULL; | 4469 | return NULL; |
4472 | } | 4470 | } |
4473 | if (! MHD_itc_nonblocking_(daemon->wpipe[0])) | 4471 | if (! MHD_itc_nonblocking_ (daemon->wpipe)) |
4474 | { | 4472 | { |
4475 | #ifdef HAVE_MESSAGES | 4473 | #ifdef HAVE_MESSAGES |
4476 | MHD_DLOG (daemon, | 4474 | MHD_DLOG (daemon, |
4477 | _("Failed to make read side of inter-thread control channel non-blocking: %s\n"), | 4475 | _("Failed to make read side of inter-thread control channel non-blocking: %s\n"), |
4478 | MHD_pipe_last_strerror_ ()); | 4476 | MHD_pipe_last_strerror_ ()); |
4479 | #endif | 4477 | #endif |
4480 | if (0 != MHD_pipe_close_ (daemon->wpipe[0])) | 4478 | MHD_pipe_close_ (daemon->wpipe); |
4481 | MHD_PANIC (_("close failed\n")); | ||
4482 | if (0 != MHD_pipe_close_ (daemon->wpipe[1])) | ||
4483 | MHD_PANIC (_("close failed\n")); | ||
4484 | free (daemon); | 4479 | free (daemon); |
4485 | return NULL; | 4480 | return NULL; |
4486 | } | 4481 | } |
4487 | if (!MHD_itc_nonblocking_(daemon->wpipe[1])) | ||
4488 | { | ||
4489 | #ifdef HAVE_MESSAGES | ||
4490 | MHD_DLOG (daemon, | ||
4491 | _("Failed to make write side of inter-thread control channel non-blocking: %s\n"), | ||
4492 | MHD_pipe_last_strerror_ ()); | ||
4493 | #endif | ||
4494 | } | ||
4495 | } | 4482 | } |
4496 | if ( (0 == (flags & (MHD_USE_POLL | MHD_USE_EPOLL))) && | 4483 | if ( (0 == (flags & (MHD_USE_POLL | MHD_USE_EPOLL))) && |
4497 | (1 == use_pipe) && | 4484 | (1 == use_pipe) && |
4498 | (! MHD_SCKT_FD_FITS_FDSET_(daemon->wpipe[0], | 4485 | (! MHD_SCKT_FD_FITS_FDSET_(MHD_pipe_get_read_fd_ (daemon->wpipe), |
4499 | NULL)) ) | 4486 | NULL)) ) |
4500 | { | 4487 | { |
4501 | #ifdef HAVE_MESSAGES | 4488 | #ifdef HAVE_MESSAGES |
4502 | MHD_DLOG (daemon, | 4489 | MHD_DLOG (daemon, |
4503 | _("file descriptor for control pipe exceeds maximum value\n")); | 4490 | _("file descriptor for control pipe exceeds maximum value\n")); |
4504 | #endif | 4491 | #endif |
4505 | if (0 != MHD_pipe_close_ (daemon->wpipe[0])) | 4492 | MHD_pipe_close_ (daemon->wpipe); |
4506 | MHD_PANIC (_("close failed\n")); | ||
4507 | if (0 != MHD_pipe_close_ (daemon->wpipe[1])) | ||
4508 | MHD_PANIC (_("close failed\n")); | ||
4509 | free (daemon); | 4493 | free (daemon); |
4510 | return NULL; | 4494 | return NULL; |
4511 | } | 4495 | } |
@@ -5005,7 +4989,7 @@ MHD_start_daemon_va (unsigned int flags, | |||
5005 | #endif | 4989 | #endif |
5006 | goto thread_failed; | 4990 | goto thread_failed; |
5007 | } | 4991 | } |
5008 | if (! MHD_itc_nonblocking_(d->wpipe[0])) | 4992 | if (! MHD_itc_nonblocking_(d->wpipe)) |
5009 | { | 4993 | { |
5010 | #ifdef HAVE_MESSAGES | 4994 | #ifdef HAVE_MESSAGES |
5011 | MHD_DLOG (daemon, | 4995 | MHD_DLOG (daemon, |
@@ -5014,27 +4998,16 @@ MHD_start_daemon_va (unsigned int flags, | |||
5014 | #endif | 4998 | #endif |
5015 | goto thread_failed; | 4999 | goto thread_failed; |
5016 | } | 5000 | } |
5017 | if (! MHD_itc_nonblocking_(d->wpipe[1])) | ||
5018 | { | ||
5019 | #ifdef HAVE_MESSAGES | ||
5020 | MHD_DLOG (daemon, | ||
5021 | _("Failed to make write side of worker inter-thread control channel non-blocking: %s\n"), | ||
5022 | MHD_pipe_last_strerror_ ()); | ||
5023 | #endif | ||
5024 | } | ||
5025 | } | 5001 | } |
5026 | if ( (0 == (flags & (MHD_USE_POLL | MHD_USE_EPOLL))) && | 5002 | if ( (0 == (flags & (MHD_USE_POLL | MHD_USE_EPOLL))) && |
5027 | (! MHD_SCKT_FD_FITS_FDSET_(d->wpipe[0], | 5003 | (! MHD_SCKT_FD_FITS_FDSET_(MHD_pipe_get_read_fd_ (daemon->wpipe), |
5028 | NULL)) ) | 5004 | NULL)) ) |
5029 | { | 5005 | { |
5030 | #ifdef HAVE_MESSAGES | 5006 | #ifdef HAVE_MESSAGES |
5031 | MHD_DLOG (daemon, | 5007 | MHD_DLOG (daemon, |
5032 | _("File descriptor for worker control pipe exceeds maximum value\n")); | 5008 | _("File descriptor for worker control pipe exceeds maximum value\n")); |
5033 | #endif | 5009 | #endif |
5034 | if (0 != MHD_pipe_close_ (d->wpipe[0])) | 5010 | MHD_pipe_close_ (d->wpipe); |
5035 | MHD_PANIC (_("close failed\n")); | ||
5036 | if (0 != MHD_pipe_close_ (d->wpipe[1])) | ||
5037 | MHD_PANIC (_("close failed\n")); | ||
5038 | goto thread_failed; | 5011 | goto thread_failed; |
5039 | } | 5012 | } |
5040 | 5013 | ||
@@ -5140,12 +5113,8 @@ thread_failed: | |||
5140 | if (0 != (flags & MHD_USE_SSL)) | 5113 | if (0 != (flags & MHD_USE_SSL)) |
5141 | gnutls_priority_deinit (daemon->priority_cache); | 5114 | gnutls_priority_deinit (daemon->priority_cache); |
5142 | #endif | 5115 | #endif |
5143 | if ( (MHD_INVALID_PIPE_ != daemon->wpipe[0]) && | 5116 | if (! MHD_INVALID_PIPE_(daemon->wpipe)) |
5144 | (0 != MHD_pipe_close_ (daemon->wpipe[0])) ) | 5117 | MHD_pipe_close_ (daemon->wpipe); |
5145 | MHD_PANIC (_("close failed\n")); | ||
5146 | if ( (MHD_INVALID_PIPE_ != daemon->wpipe[1]) && | ||
5147 | (0 != MHD_pipe_close_ (daemon->wpipe[1])) ) | ||
5148 | MHD_PANIC (_("close failed\n")); | ||
5149 | free (daemon); | 5118 | free (daemon); |
5150 | return NULL; | 5119 | return NULL; |
5151 | } | 5120 | } |
@@ -5212,8 +5181,8 @@ close_all_connections (struct MHD_Daemon *daemon) | |||
5212 | shutdown (pos->socket_fd, SHUT_RDWR); | 5181 | shutdown (pos->socket_fd, SHUT_RDWR); |
5213 | #if MHD_WINSOCK_SOCKETS | 5182 | #if MHD_WINSOCK_SOCKETS |
5214 | if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && | 5183 | if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && |
5215 | (MHD_INVALID_PIPE_ != daemon->wpipe[1]) && | 5184 | (! MHD_INVALID_PIPE_(daemon->wpipe)) && |
5216 | (1 != MHD_pipe_write_ (daemon->wpipe[1], "e", 1)) ) | 5185 | (1 != MHD_pipe_write_ (daemon->wpipe, "e", 1)) ) |
5217 | MHD_PANIC (_("Failed to signal shutdown via pipe")); | 5186 | MHD_PANIC (_("Failed to signal shutdown via pipe")); |
5218 | #endif | 5187 | #endif |
5219 | } | 5188 | } |
@@ -5253,7 +5222,7 @@ close_all_connections (struct MHD_Daemon *daemon) | |||
5253 | 5222 | ||
5254 | #ifdef EPOLL_SUPPORT | 5223 | #ifdef EPOLL_SUPPORT |
5255 | /** | 5224 | /** |
5256 | * Shutdown epoll()-event loop by adding 'wpipe' to its event set. | 5225 | * Shutdown epoll()-event loop by adding write end of 'wpipe' to its event set. |
5257 | * | 5226 | * |
5258 | * @param daemon daemon of which the epoll() instance must be signalled | 5227 | * @param daemon daemon of which the epoll() instance must be signalled |
5259 | */ | 5228 | */ |
@@ -5262,7 +5231,7 @@ epoll_shutdown (struct MHD_Daemon *daemon) | |||
5262 | { | 5231 | { |
5263 | struct epoll_event event; | 5232 | struct epoll_event event; |
5264 | 5233 | ||
5265 | if (MHD_INVALID_PIPE_ == daemon->wpipe[1]) | 5234 | if (MHD_INVALID_PIPE_(daemon->wpipe)) |
5266 | { | 5235 | { |
5267 | /* wpipe was required in this mode, how could this happen? */ | 5236 | /* wpipe was required in this mode, how could this happen? */ |
5268 | MHD_PANIC (_("Internal error\n")); | 5237 | MHD_PANIC (_("Internal error\n")); |
@@ -5271,7 +5240,7 @@ epoll_shutdown (struct MHD_Daemon *daemon) | |||
5271 | event.data.ptr = NULL; | 5240 | event.data.ptr = NULL; |
5272 | if (0 != epoll_ctl (daemon->epoll_fd, | 5241 | if (0 != epoll_ctl (daemon->epoll_fd, |
5273 | EPOLL_CTL_ADD, | 5242 | EPOLL_CTL_ADD, |
5274 | daemon->wpipe[1], | 5243 | MHD_pipe_get_write_fd_ (daemon->wpipe), |
5275 | &event)) | 5244 | &event)) |
5276 | MHD_PANIC (_("Failed to add wpipe to epoll set to signal termination\n")); | 5245 | MHD_PANIC (_("Failed to add wpipe to epoll set to signal termination\n")); |
5277 | } | 5246 | } |
@@ -5314,9 +5283,9 @@ MHD_stop_daemon (struct MHD_Daemon *daemon) | |||
5314 | #endif | 5283 | #endif |
5315 | } | 5284 | } |
5316 | } | 5285 | } |
5317 | if (MHD_INVALID_PIPE_ != daemon->wpipe[1]) | 5286 | if (! MHD_INVALID_PIPE_(daemon->wpipe)) |
5318 | { | 5287 | { |
5319 | if (1 != MHD_pipe_write_ (daemon->wpipe[1], "e", 1)) | 5288 | if (1 != MHD_pipe_write_ (daemon->wpipe, "e", 1)) |
5320 | MHD_PANIC (_("Failed to signal shutdown via pipe")); | 5289 | MHD_PANIC (_("Failed to signal shutdown via pipe")); |
5321 | } | 5290 | } |
5322 | #ifdef HAVE_LISTEN_SHUTDOWN | 5291 | #ifdef HAVE_LISTEN_SHUTDOWN |
@@ -5350,9 +5319,9 @@ MHD_stop_daemon (struct MHD_Daemon *daemon) | |||
5350 | /* MHD_USE_NO_LISTEN_SOCKET disables thread pools, hence we need to check */ | 5319 | /* MHD_USE_NO_LISTEN_SOCKET disables thread pools, hence we need to check */ |
5351 | for (i = 0; i < daemon->worker_pool_size; ++i) | 5320 | for (i = 0; i < daemon->worker_pool_size; ++i) |
5352 | { | 5321 | { |
5353 | if (MHD_INVALID_PIPE_ != daemon->worker_pool[i].wpipe[1]) | 5322 | if (! MHD_INVALID_PIPE_(daemon->worker_pool[i].wpipe)) |
5354 | { | 5323 | { |
5355 | if (1 != MHD_pipe_write_ (daemon->worker_pool[i].wpipe[1], | 5324 | if (1 != MHD_pipe_write_ (daemon->worker_pool[i].wpipe, |
5356 | "e", | 5325 | "e", |
5357 | 1)) | 5326 | 1)) |
5358 | MHD_PANIC (_("Failed to signal shutdown via pipe.")); | 5327 | MHD_PANIC (_("Failed to signal shutdown via pipe.")); |
@@ -5372,12 +5341,9 @@ MHD_stop_daemon (struct MHD_Daemon *daemon) | |||
5372 | /* Individual pipes are always used */ | 5341 | /* Individual pipes are always used */ |
5373 | if (1) | 5342 | if (1) |
5374 | { | 5343 | { |
5375 | if (MHD_INVALID_PIPE_ != daemon->worker_pool[i].wpipe[1]) | 5344 | if (! MHD_INVALID_PIPE_ (daemon->worker_pool[i].wpipe) ) |
5376 | { | 5345 | { |
5377 | if (0 != MHD_pipe_close_ (daemon->worker_pool[i].wpipe[0])) | 5346 | MHD_pipe_close_ (daemon->worker_pool[i].wpipe); |
5378 | MHD_PANIC (_("close failed\n")); | ||
5379 | if (0 != MHD_pipe_close_ (daemon->worker_pool[i].wpipe[1])) | ||
5380 | MHD_PANIC (_("close failed\n")); | ||
5381 | } | 5347 | } |
5382 | } | 5348 | } |
5383 | } | 5349 | } |
@@ -5432,13 +5398,8 @@ MHD_stop_daemon (struct MHD_Daemon *daemon) | |||
5432 | MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex); | 5398 | MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex); |
5433 | MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); | 5399 | MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); |
5434 | 5400 | ||
5435 | if (MHD_INVALID_PIPE_ != daemon->wpipe[1]) | 5401 | if (! MHD_INVALID_PIPE_(daemon->wpipe)) |
5436 | { | 5402 | MHD_pipe_close_ (daemon->wpipe); |
5437 | if (0 != MHD_pipe_close_ (daemon->wpipe[0])) | ||
5438 | MHD_PANIC (_("close failed\n")); | ||
5439 | if (0 != MHD_pipe_close_ (daemon->wpipe[1])) | ||
5440 | MHD_PANIC (_("close failed\n")); | ||
5441 | } | ||
5442 | free (daemon); | 5403 | free (daemon); |
5443 | } | 5404 | } |
5444 | 5405 | ||