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))
143 unsigned int num_connections;
146 #if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
147 struct MHD_UpgradeResponseHandle *urh;
148 struct MHD_UpgradeResponseHandle *urhn;
152 (MHD_resume_suspended_connections_ (daemon)) )
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)
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 & POLLOUT),
301 0 != (p[poll_server+i].revents & MHD_POLL_REVENTS_ERR_DISC));
304 #if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
305 for (urh = daemon->urh_tail;
NULL != urh; urh = urhn)
307 if (i >= num_connections)
314 if ((p[poll_server+i].
fd != urh->connection->socket_fd) ||
315 (p[poll_server+i+1].fd != urh->mhd.socket))
317 urh_from_pollfd (urh,
320 MHD_upgrade_response_handle_process_ (urh);
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) )
330 urh->clean_ready =
true;
340 if ( (-1 != poll_listen) &&
341 (0 != (p[poll_listen].revents & POLLIN)) )
358 MHD_daemon_poll_listen_socket_ (
struct MHD_Daemon *daemon,
363 unsigned int poll_count;
378 p[poll_count].fd = ls;
379 p[poll_count].events = POLLIN;
380 p[poll_count].revents = 0;
381 poll_listen = poll_count;
384 if (MHD_ITC_IS_VALID_(daemon->
itc))
386 p[poll_count].fd = MHD_itc_r_fd_ (daemon->
itc);
387 p[poll_count].events = POLLIN;
388 p[poll_count].revents = 0;
389 poll_itc_idx = poll_count;
394 (void) MHD_resume_suspended_connections_ (daemon);
412 MHD_SC_UNEXPECTED_POLL_ERROR,
413 _(
"poll failed: %s\n"),
416 return MHD_SC_UNEXPECTED_POLL_ERROR;
418 if ( (-1 != poll_itc_idx) &&
419 (0 != (p[poll_itc_idx].revents & POLLIN)) )
420 MHD_itc_clear_ (daemon->
itc);
424 return MHD_SC_DAEMON_ALREADY_SHUTDOWN;
425 if ( (-1 != poll_listen) &&
426 (0 != (p[poll_listen].revents & POLLIN)) )
446 return MHD_SC_DAEMON_ALREADY_SHUTDOWN;
448 return MHD_daemon_poll_all_ (daemon,
450 return MHD_daemon_poll_listen_socket_ (daemon,
455 return MHD_SC_POLL_NOT_SUPPORTED;
469 MHD_daemon_upgrade_connection_with_poll_ (
struct MHD_Connection *con)
471 struct MHD_UpgradeResponseHandle *urh = con->
request.urh;
477 p[0].fd = urh->connection->socket_fd;
478 p[1].fd = urh->mhd.socket;
480 while ( (0 != urh->in_buffer_size) ||
481 (0 != urh->out_buffer_size) ||
482 (0 != urh->in_buffer_used) ||
483 (0 != urh->out_buffer_used) )
487 urh_update_pollfd (urh,
491 (urh->in_buffer_used < urh->in_buffer_size))
496 if (MHD_sys_poll_ (p,
506 MHD_SC_UNEXPECTED_POLL_ERROR,
507 _(
"Error during poll: `%s'\n"),
512 urh_from_pollfd (urh,
514 MHD_upgrade_response_handle_process_ (urh);
struct MHD_Request request
bool data_already_pending
MHD_mutex_lock_chk_ & daemon
unsigned int global_connection_limit
#define MHD_socket_get_error_()
void * MHD_calloc_(size_t nelem, size_t elsize)
#define MHD_socket_strerr_(err)
struct MHD_Connection * prev
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)
#define MHD_connection_finish_forward_(conn)
non-public functions provided by daemon_poll.c
bool disallow_suspend_resume
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()