diff options
Diffstat (limited to 'src/lib/daemon_quiesce.c')
-rw-r--r-- | src/lib/daemon_quiesce.c | 103 |
1 files changed, 52 insertions, 51 deletions
diff --git a/src/lib/daemon_quiesce.c b/src/lib/daemon_quiesce.c index 0d920608..c7275099 100644 --- a/src/lib/daemon_quiesce.c +++ b/src/lib/daemon_quiesce.c | |||
@@ -54,75 +54,76 @@ MHD_daemon_quiesce (struct MHD_Daemon *daemon) | |||
54 | return MHD_INVALID_SOCKET; | 54 | return MHD_INVALID_SOCKET; |
55 | if ( (daemon->disable_itc) && | 55 | if ( (daemon->disable_itc) && |
56 | (MHD_TM_EXTERNAL_EVENT_LOOP != daemon->threading_mode) ) | 56 | (MHD_TM_EXTERNAL_EVENT_LOOP != daemon->threading_mode) ) |
57 | { | 57 | { |
58 | #ifdef HAVE_MESSAGES | 58 | #ifdef HAVE_MESSAGES |
59 | MHD_DLOG (daemon, | 59 | MHD_DLOG (daemon, |
60 | MHD_SC_SYSCALL_QUIESCE_REQUIRES_ITC, | 60 | MHD_SC_SYSCALL_QUIESCE_REQUIRES_ITC, |
61 | "Using MHD_quiesce_daemon in this mode requires ITC\n"); | 61 | "Using MHD_quiesce_daemon in this mode requires ITC\n"); |
62 | #endif | 62 | #endif |
63 | return MHD_INVALID_SOCKET; | 63 | return MHD_INVALID_SOCKET; |
64 | } | 64 | } |
65 | 65 | ||
66 | if (NULL != daemon->worker_pool) | 66 | if (NULL != daemon->worker_pool) |
67 | { | ||
68 | unsigned int i; | ||
69 | |||
70 | for (i = 0; i < daemon->worker_pool_size; i++) | ||
67 | { | 71 | { |
68 | unsigned int i; | 72 | struct MHD_Daemon *worker = &daemon->worker_pool[i]; |
69 | 73 | ||
70 | for (i = 0; i < daemon->worker_pool_size; i++) | 74 | worker->was_quiesced = true; |
71 | { | ||
72 | struct MHD_Daemon *worker = &daemon->worker_pool[i]; | ||
73 | |||
74 | worker->was_quiesced = true; | ||
75 | #ifdef EPOLL_SUPPORT | ||
76 | if ( (MHD_ELS_EPOLL == daemon->event_loop_syscall) && | ||
77 | (-1 != worker->epoll_fd) && | ||
78 | (worker->listen_socket_in_epoll) ) | ||
79 | { | ||
80 | if (0 != epoll_ctl (worker->epoll_fd, | ||
81 | EPOLL_CTL_DEL, | ||
82 | listen_socket, | ||
83 | NULL)) | ||
84 | MHD_PANIC (_("Failed to remove listen FD from epoll set\n")); | ||
85 | worker->listen_socket_in_epoll = false; | ||
86 | } | ||
87 | else | ||
88 | #endif | ||
89 | if (MHD_ITC_IS_VALID_(worker->itc)) | ||
90 | { | ||
91 | if (! MHD_itc_activate_ (worker->itc, | ||
92 | "q")) | ||
93 | MHD_PANIC (_("Failed to signal quiesce via inter-thread communication channel")); | ||
94 | } | ||
95 | } | ||
96 | daemon->was_quiesced = true; | ||
97 | #ifdef EPOLL_SUPPORT | 75 | #ifdef EPOLL_SUPPORT |
98 | if ( (MHD_ELS_EPOLL == daemon->event_loop_syscall) && | 76 | if ( (MHD_ELS_EPOLL == daemon->event_loop_syscall) && |
99 | (-1 != daemon->epoll_fd) && | 77 | (-1 != worker->epoll_fd) && |
100 | (daemon->listen_socket_in_epoll) ) | 78 | (worker->listen_socket_in_epoll) ) |
101 | { | 79 | { |
102 | if (0 != epoll_ctl (daemon->epoll_fd, | 80 | if (0 != epoll_ctl (worker->epoll_fd, |
103 | EPOLL_CTL_DEL, | 81 | EPOLL_CTL_DEL, |
104 | listen_socket, | 82 | listen_socket, |
105 | NULL)) | 83 | NULL)) |
106 | MHD_PANIC ("Failed to remove listen FD from epoll set\n"); | 84 | MHD_PANIC (_ ("Failed to remove listen FD from epoll set\n")); |
107 | daemon->listen_socket_in_epoll = false; | 85 | worker->listen_socket_in_epoll = false; |
108 | } | 86 | } |
87 | else | ||
109 | #endif | 88 | #endif |
89 | if (MHD_ITC_IS_VALID_ (worker->itc)) | ||
90 | { | ||
91 | if (! MHD_itc_activate_ (worker->itc, | ||
92 | "q")) | ||
93 | MHD_PANIC (_ ( | ||
94 | "Failed to signal quiesce via inter-thread communication channel")); | ||
95 | } | ||
110 | } | 96 | } |
111 | 97 | daemon->was_quiesced = true; | |
112 | if ( (MHD_ITC_IS_VALID_(daemon->itc)) && | 98 | #ifdef EPOLL_SUPPORT |
99 | if ( (MHD_ELS_EPOLL == daemon->event_loop_syscall) && | ||
100 | (-1 != daemon->epoll_fd) && | ||
101 | (daemon->listen_socket_in_epoll) ) | ||
102 | { | ||
103 | if (0 != epoll_ctl (daemon->epoll_fd, | ||
104 | EPOLL_CTL_DEL, | ||
105 | listen_socket, | ||
106 | NULL)) | ||
107 | MHD_PANIC ("Failed to remove listen FD from epoll set\n"); | ||
108 | daemon->listen_socket_in_epoll = false; | ||
109 | } | ||
110 | #endif | ||
111 | } | ||
112 | |||
113 | if ( (MHD_ITC_IS_VALID_ (daemon->itc)) && | ||
113 | (! MHD_itc_activate_ (daemon->itc, | 114 | (! MHD_itc_activate_ (daemon->itc, |
114 | "q")) ) | 115 | "q")) ) |
115 | MHD_PANIC (_("Failed to signal quiesce via inter-thread communication channel")); | 116 | MHD_PANIC (_ ( |
117 | "Failed to signal quiesce via inter-thread communication channel")); | ||
116 | 118 | ||
117 | /* FIXME: we might want some bi-directional communication here | 119 | /* FIXME: we might want some bi-directional communication here |
118 | (in both the thread-pool and single-thread case!) | 120 | (in both the thread-pool and single-thread case!) |
119 | to be sure that the threads have stopped using the listen | 121 | to be sure that the threads have stopped using the listen |
120 | socket, otherwise there is still the possibility of a race | 122 | socket, otherwise there is still the possibility of a race |
121 | between a thread accept()ing and the caller closing and | 123 | between a thread accept()ing and the caller closing and |
122 | re-binding the socket. */ | 124 | re-binding the socket. */ |
123 | 125 | ||
124 | return listen_socket; | 126 | return listen_socket; |
125 | } | 127 | } |
126 | 128 | ||
127 | /* end of daemon_quiesce.c */ | 129 | /* end of daemon_quiesce.c */ |
128 | |||