36 #if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 47 urh_update_pollfd (
struct MHD_UpgradeResponseHandle *urh,
53 if (urh->in_buffer_used < urh->in_buffer_size)
54 p[0].events |= POLLIN;
55 if (0 != urh->out_buffer_used)
56 p[0].events |= POLLOUT;
61 ((0 != urh->in_buffer_size) ||
62 (0 != urh->out_buffer_size) ||
63 (0 != urh->out_buffer_used)))
64 p[0].events |= MHD_POLL_EVENTS_ERR_DISC;
66 if (urh->out_buffer_used < urh->out_buffer_size)
67 p[1].events |= POLLIN;
68 if (0 != urh->in_buffer_used)
69 p[1].events |= POLLOUT;
74 ((0 != urh->out_buffer_size) ||
75 (0 != urh->in_buffer_size) ||
76 (0 != urh->in_buffer_used)))
77 p[1].events |= MHD_POLL_EVENTS_ERR_DISC;
88 urh_to_pollfd (
struct MHD_UpgradeResponseHandle *urh,
91 p[0].fd = urh->connection->socket_fd;
92 p[1].fd = urh->mhd.socket;
93 urh_update_pollfd (urh,
104 urh_from_pollfd (
struct MHD_UpgradeResponseHandle *urh,
111 if (0 != (p[0].revents & POLLIN))
113 if (0 != (p[0].revents & POLLOUT))
115 if (0 != (p[0].revents & POLLHUP))
117 if (0 != (p[0].revents & MHD_POLL_REVENTS_ERRROR))
119 if (0 != (p[1].revents & POLLIN))
121 if (0 != (p[1].revents & POLLOUT))
123 if (0 != (p[1].revents & POLLHUP))
125 if (0 != (p[1].revents & MHD_POLL_REVENTS_ERRROR))
140 MHD_daemon_poll_all_ (
struct MHD_Daemon *daemon,
143 unsigned int num_connections;
146 #if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 147 struct MHD_UpgradeResponseHandle *urh;
148 struct MHD_UpgradeResponseHandle *urhn;
159 #if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 160 for (urh = daemon->urh_head;
NULL != urh; urh = urh->next)
161 num_connections += 2;
167 unsigned int poll_server;
174 sizeof (
struct pollfd));
179 MHD_SC_POLL_MALLOC_FAILURE,
180 _ (
"Error allocating memory: %s\n"),
183 return MHD_SC_POLL_MALLOC_FAILURE;
193 p[poll_server].fd = ls;
194 p[poll_server].events = POLLIN;
195 p[poll_server].revents = 0;
196 poll_listen = (int) poll_server;
200 if (MHD_ITC_IS_VALID_ (daemon->
itc))
202 p[poll_server].fd = MHD_itc_r_fd_ (daemon->
itc);
203 p[poll_server].events = POLLIN;
204 p[poll_server].revents = 0;
205 poll_itc_idx = (int) poll_server;
210 else if ( (MHD_TM_THREAD_PER_CONNECTION == daemon->
threading_mode) ||
216 timeout = (ltimeout > INT_MAX) ? INT_MAX : (
int) ltimeout;
225 p[poll_server + i].events |= POLLIN | MHD_POLL_EVENTS_ERR_DISC;
228 p[poll_server + i].events |= POLLOUT | MHD_POLL_EVENTS_ERR_DISC;
231 p[poll_server + i].events |= MHD_POLL_EVENTS_ERR_DISC;
239 #if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 240 for (urh = daemon->urh_tail;
NULL != urh; urh = urh->prev)
243 &(p[poll_server + i]));
247 if (0 == poll_server + num_connections)
252 if (MHD_sys_poll_ (p,
253 poll_server + num_connections,
264 MHD_SC_UNEXPECTED_POLL_ERROR,
265 _ (
"poll failed: %s\n"),
269 return MHD_SC_UNEXPECTED_POLL_ERROR;
278 if ( (-1 != poll_itc_idx) &&
279 (0 != (p[poll_itc_idx].revents & POLLIN)) )
280 MHD_itc_clear_ (daemon->
itc);
286 return MHD_SC_DAEMON_ALREADY_SHUTDOWN;
290 while (
NULL != (pos = prev))
294 if (i >= num_connections)
299 0 != (p[poll_server + i].revents & POLLIN),
300 0 != (p[poll_server + i].revents
302 0 != (p[poll_server + i].revents
303 & MHD_POLL_REVENTS_ERR_DISC));
306 #if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 307 for (urh = daemon->urh_tail;
NULL != urh; urh = urhn)
309 if (i >= num_connections)
316 if ((p[poll_server + i].
fd != urh->connection->socket_fd) ||
317 (p[poll_server + i + 1].fd != urh->mhd.socket))
319 urh_from_pollfd (urh,
320 &p[poll_server + i]);
322 MHD_upgrade_response_handle_process_ (urh);
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) )
332 urh->clean_ready =
true;
342 if ( (-1 != poll_listen) &&
343 (0 != (p[poll_listen].revents & POLLIN)) )
360 MHD_daemon_poll_listen_socket_ (
struct MHD_Daemon *daemon,
365 unsigned int poll_count;
380 p[poll_count].fd = ls;
381 p[poll_count].events = POLLIN;
382 p[poll_count].revents = 0;
383 poll_listen = poll_count;
386 if (MHD_ITC_IS_VALID_ (daemon->
itc))
388 p[poll_count].fd = MHD_itc_r_fd_ (daemon->
itc);
389 p[poll_count].events = POLLIN;
390 p[poll_count].revents = 0;
391 poll_itc_idx = poll_count;
404 if (MHD_sys_poll_ (p,
414 MHD_SC_UNEXPECTED_POLL_ERROR,
415 _ (
"poll failed: %s\n"),
418 return MHD_SC_UNEXPECTED_POLL_ERROR;
420 if ( (-1 != poll_itc_idx) &&
421 (0 != (p[poll_itc_idx].revents & POLLIN)) )
422 MHD_itc_clear_ (daemon->
itc);
426 return MHD_SC_DAEMON_ALREADY_SHUTDOWN;
427 if ( (-1 != poll_listen) &&
428 (0 != (p[poll_listen].revents & POLLIN)) )
448 return MHD_SC_DAEMON_ALREADY_SHUTDOWN;
450 return MHD_daemon_poll_all_ (daemon,
452 return MHD_daemon_poll_listen_socket_ (daemon,
457 return MHD_SC_POLL_NOT_SUPPORTED;
471 MHD_daemon_upgrade_connection_with_poll_ (
struct MHD_Connection *con)
473 struct MHD_UpgradeResponseHandle *urh = con->
request.urh;
479 p[0].fd = urh->connection->socket_fd;
480 p[1].fd = urh->mhd.socket;
482 while ( (0 != urh->in_buffer_size) ||
483 (0 != urh->out_buffer_size) ||
484 (0 != urh->in_buffer_used) ||
485 (0 != urh->out_buffer_used) )
489 urh_update_pollfd (urh,
493 (urh->in_buffer_used < urh->in_buffer_size))
498 if (MHD_sys_poll_ (p,
508 MHD_SC_UNEXPECTED_POLL_ERROR,
509 _ (
"Error during poll: `%s'\n"),
514 urh_from_pollfd (urh,
516 MHD_upgrade_response_handle_process_ (urh);
struct MHD_Request request
bool data_already_pending
unsigned int global_connection_limit
#define MHD_socket_get_error_()
void * MHD_calloc_(size_t nelem, size_t elsize)
#define MHD_socket_strerr_(err)
internal shared structures
#define MHD_UNSIGNED_LONG_LONG
struct MHD_Daemon * daemon
struct MHD_Connection * next
struct MHD_Connection * connections_tail
enum MHD_StatusCode MHD_daemon_get_timeout(struct MHD_Daemon *daemon, MHD_UNSIGNED_LONG_LONG *timeout)
#define MHD_INVALID_SOCKET
struct MHD_Connection * connections_head
complete upgrade socket forwarding operation in TLS mode
enum MHD_RequestEventLoopInfo event_loop_info
function to call event handlers based on event mask
enum MHD_StatusCode MHD_accept_connection_(struct MHD_Daemon *daemon)
struct MHD_Connection * prev
enum MHD_StatusCode MHD_daemon_poll_(struct MHD_Daemon *daemon, bool may_block)
#define MHD_strerror_(errnum)
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)
non-public functions provided by daemon_poll.c
bool disallow_suspend_resume
bool MHD_resume_suspended_connections_(struct MHD_Daemon *daemon)
enum MHD_ThreadingMode threading_mode
#define MHD_SCKT_ERR_IS_EINTR_(err)
function to process upgrade activity (over TLS)
functions to add connection to our active set
implementation of MHD_request_resume()