43 #define MAX_EVENTS 128 46 #if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 56 is_urh_ready (
struct MHD_UpgradeResponseHandle *
const urh)
60 if ( (0 == urh->in_buffer_size) &&
61 (0 == urh->out_buffer_size) &&
62 (0 == urh->in_buffer_used) &&
63 (0 == urh->out_buffer_used) )
71 (urh->in_buffer_used < urh->in_buffer_size) )
75 (urh->out_buffer_used < urh->out_buffer_size) )
79 (urh->out_buffer_used > 0) )
83 (urh->in_buffer_used > 0) )
101 static enum MHD_StatusCode
104 struct epoll_event events[MAX_EVENTS];
106 struct MHD_UpgradeResponseHandle * pos;
107 struct MHD_UpgradeResponseHandle * prev;
109 num_events = MAX_EVENTS;
110 while (MAX_EVENTS == num_events)
115 num_events = epoll_wait (daemon->epoll_upgrade_fd,
119 if (-1 == num_events)
126 MHD_SC_UNEXPECTED_EPOLL_WAIT_ERROR,
127 _(
"Call to epoll_wait failed: %s\n"),
130 return MHD_SC_UNEXPECTED_EPOLL_WAIT_ERROR;
132 for (i = 0; i < (
unsigned int) num_events; i++)
134 struct UpgradeEpollHandle *
const ueh = events[i].data.ptr;
135 struct MHD_UpgradeResponseHandle *
const urh = ueh->urh;
136 bool new_err_state =
false;
138 if (urh->clean_ready)
142 if (0 != (events[i].events & EPOLLIN))
144 if (0 != (events[i].events & EPOLLOUT))
146 if (0 != (events[i].events & EPOLLHUP))
150 (0 != (events[i].events & (EPOLLERR | EPOLLPRI))) )
156 new_err_state =
true;
159 if (! urh->in_eready_list)
165 daemon->eready_urh_tail,
167 urh->in_eready_list =
true;
172 prev = daemon->eready_urh_tail;
173 while (
NULL != (pos = prev))
176 MHD_upgrade_response_handle_process_ (pos);
177 if (! is_urh_ready(pos))
180 daemon->eready_urh_tail,
182 pos->in_eready_list =
false;
185 if ( (0 == pos->in_buffer_size) &&
186 (0 == pos->out_buffer_size) &&
187 (0 == pos->in_buffer_used) &&
188 (0 == pos->out_buffer_used) )
191 pos->clean_ready =
true;
217 #if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 218 static const char *
const upgrade_marker =
"upgrade_ptr";
222 struct epoll_event events[MAX_EVENTS];
223 struct epoll_event event;
229 #if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 230 bool run_upgraded =
false;
233 if (-1 == daemon->epoll_fd)
234 return MHD_SC_EPOLL_FD_INVALID;
236 return MHD_SC_DAEMON_ALREADY_SHUTDOWN;
240 (! daemon->listen_socket_in_epoll) &&
243 event.events = EPOLLIN;
244 event.data.ptr = daemon;
245 if (0 != epoll_ctl (daemon->epoll_fd,
252 MHD_SC_EPOLL_CTL_ADD_FAILED,
253 _(
"Call to epoll_ctl failed: %s\n"),
256 return MHD_SC_EPOLL_CTL_ADD_FAILED;
258 daemon->listen_socket_in_epoll =
true;
261 (daemon->listen_socket_in_epoll) )
263 if (0 != epoll_ctl (daemon->epoll_fd,
267 MHD_PANIC (
"Failed to remove listen FD from epoll set\n");
268 daemon->listen_socket_in_epoll =
false;
271 #if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 272 if ( (! daemon->upgrade_fd_in_epoll) &&
273 (-1 != daemon->epoll_upgrade_fd) )
275 event.events = EPOLLIN | EPOLLOUT;
276 event.data.ptr = (
void *) upgrade_marker;
277 if (0 != epoll_ctl (daemon->epoll_fd,
279 daemon->epoll_upgrade_fd,
284 MHD_SC_EPOLL_CTL_ADD_FAILED,
285 _(
"Call to epoll_ctl failed: %s\n"),
288 return MHD_SC_EPOLL_CTL_ADD_FAILED;
290 daemon->upgrade_fd_in_epoll =
true;
293 if ( (daemon->listen_socket_in_epoll) &&
300 if (0 != epoll_ctl (daemon->epoll_fd,
304 MHD_PANIC (
_(
"Failed to remove listen FD from epoll set\n"));
305 daemon->listen_socket_in_epoll =
false;
319 timeout_ms = INT_MAX;
321 timeout_ms = (int) timeout_ll;
338 num_events = MAX_EVENTS;
339 while (MAX_EVENTS == num_events)
342 num_events = epoll_wait (daemon->epoll_fd,
346 if (-1 == num_events)
353 MHD_SC_UNEXPECTED_EPOLL_WAIT_ERROR,
354 _(
"Call to epoll_wait failed: %s\n"),
357 return MHD_SC_UNEXPECTED_EPOLL_WAIT_ERROR;
359 for (i=0;i<(
unsigned int) num_events;i++)
365 #if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 366 if (upgrade_marker == events[i].
data.ptr)
374 if (daemon->epoll_itc_marker == events[i].data.ptr)
378 MHD_itc_clear_ (daemon->
itc);
381 if (daemon == events[i].
data.ptr)
385 if (0 == (events[i].events & (EPOLLERR | EPOLLHUP)))
387 unsigned int series_length = 0;
392 while ( (MHD_SC_OK ==
394 (series_length < 10) &&
404 pos = events[i].data.ptr;
406 if (0 != (events[i].events & (EPOLLPRI | EPOLLERR | EPOLLHUP)))
419 if (0 != (events[i].events & EPOLLIN))
432 if (0 != (events[i].events & EPOLLOUT))
448 #if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 450 run_epoll_for_upgrade (daemon);
454 prev = daemon->eready_tail;
455 while (
NULL != (pos = prev))
488 while (
NULL != (pos = prev))
498 while (
NULL != (pos = prev))
struct MHD_Request request
bool data_already_pending
struct MHD_Connection * prevX
size_t read_buffer_offset
unsigned int global_connection_limit
#define MHD_socket_get_error_()
#define MHD_socket_strerr_(err)
#define EDLL_insert(head, tail, element)
non-public functions provided by daemon_epoll.c
internal shared structures
#define MHD_UNSIGNED_LONG_LONG
struct MHD_Daemon * daemon
enum MHD_REQUEST_STATE state
#define MHD_socket_last_strerr_()
enum MHD_StatusCode MHD_daemon_get_timeout(struct MHD_Daemon *daemon, MHD_UNSIGNED_LONG_LONG *timeout)
#define MHD_INVALID_SOCKET
complete upgrade socket forwarding operation in TLS mode
enum MHD_RequestEventLoopInfo event_loop_info
#define EDLL_remove(head, tail, element)
struct MHD_Connection * manual_timeout_tail
function to call event handlers based on event mask
enum MHD_StatusCode MHD_accept_connection_(struct MHD_Daemon *daemon)
struct MHD_Connection * prev
int MHD_connection_call_handlers_(struct MHD_Connection *con, bool read_ready, bool write_ready, bool force_close)
void MHD_request_resume(struct MHD_Request *request)
void MHD_connection_finish_forward_(struct MHD_Connection *connection) MHD_NONNULL(1)
struct MHD_Connection * normal_timeout_tail
bool disallow_suspend_resume
bool MHD_resume_suspended_connections_(struct MHD_Daemon *daemon)
#define MHD_SCKT_ERR_IS_EINTR_(err)
bool MHD_request_handle_idle_(struct MHD_Request *request)
function to process upgrade activity (over TLS)
functions to add connection to our active set
implementation of MHD_request_resume()