aboutsummaryrefslogtreecommitdiff
path: root/src/lib/daemon_select.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/daemon_select.c')
-rw-r--r--src/lib/daemon_select.c92
1 files changed, 92 insertions, 0 deletions
diff --git a/src/lib/daemon_select.c b/src/lib/daemon_select.c
index 338b12d5..5d8a7ecc 100644
--- a/src/lib/daemon_select.c
+++ b/src/lib/daemon_select.c
@@ -477,6 +477,98 @@ internal_run_from_select (struct MHD_Daemon *daemon,
477} 477}
478 478
479 479
480#ifdef HTTPS_SUPPORT
481/**
482 * Process upgraded connection with a select loop.
483 * We are in our own thread, only processing @a con
484 *
485 * @param con connection to process
486 */
487void
488MHD_daemon_upgrade_connection_with_select_ (struct MHD_Connection *con)
489{
490 struct MHD_UpgradeResponseHandle *urh = con->request.urh;
491 struct MHD_Daemon *daemon = con->daemon;
492
493 while ( (0 != urh->in_buffer_size) ||
494 (0 != urh->out_buffer_size) ||
495 (0 != urh->in_buffer_used) ||
496 (0 != urh->out_buffer_used) )
497 {
498 /* use select */
499 fd_set rs;
500 fd_set ws;
501 fd_set es;
502 MHD_socket max_fd;
503 int num_ready;
504 bool result;
505
506 FD_ZERO (&rs);
507 FD_ZERO (&ws);
508 FD_ZERO (&es);
509 max_fd = MHD_INVALID_SOCKET;
510 result = urh_to_fdset (urh,
511 &rs,
512 &ws,
513 &es,
514 &max_fd,
515 FD_SETSIZE);
516 if (! result)
517 {
518#ifdef HAVE_MESSAGES
519 MHD_DLOG (con->daemon,
520 MHD_SC_SOCKET_OUTSIDE_OF_FDSET_RANGE,
521 _("Error preparing select\n"));
522#endif
523 break;
524 }
525 /* FIXME: does this check really needed? */
526 if (MHD_INVALID_SOCKET != max_fd)
527 {
528 struct timeval* tvp;
529 struct timeval tv;
530 if ( (con->tls_read_ready) &&
531 (urh->in_buffer_used < urh->in_buffer_size))
532 { /* No need to wait if incoming data is already pending in TLS buffers. */
533 tv.tv_sec = 0;
534 tv.tv_usec = 0;
535 tvp = &tv;
536 }
537 else
538 tvp = NULL;
539 num_ready = MHD_SYS_select_ (max_fd + 1,
540 &rs,
541 &ws,
542 &es,
543 tvp);
544 }
545 else
546 num_ready = 0;
547 if (num_ready < 0)
548 {
549 const int err = MHD_socket_get_error_();
550
551 if (MHD_SCKT_ERR_IS_EINTR_(err))
552 continue;
553#ifdef HAVE_MESSAGES
554 MHD_DLOG (con->daemon,
555 MHD_SC_UNEXPECTED_SELECT_ERROR,
556 _("Error during select (%d): `%s'\n"),
557 err,
558 MHD_socket_strerr_ (err));
559#endif
560 break;
561 }
562 urh_from_fdset (urh,
563 &rs,
564 &ws,
565 &es);
566 process_urh (urh);
567 }
568}
569#endif
570
571
480/** 572/**
481 * Run webserver operations. This method should be called by clients 573 * Run webserver operations. This method should be called by clients
482 * in combination with #MHD_get_fdset and #MHD_get_timeout() if the 574 * in combination with #MHD_get_fdset and #MHD_get_timeout() if the