aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/daemon.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/daemon.c')
-rw-r--r--src/microhttpd/daemon.c99
1 files changed, 73 insertions, 26 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 3afeda69..79e8ab70 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -654,14 +654,15 @@ MHD_get_fdset2 (struct MHD_Daemon *daemon,
654 unsigned int fd_setsize) 654 unsigned int fd_setsize)
655{ 655{
656 struct MHD_Connection *pos; 656 struct MHD_Connection *pos;
657 struct MHD_UpgradeResponseHandle *urh;
657 int result = MHD_YES; 658 int result = MHD_YES;
658 659
659 if ( (NULL == daemon) 660 if ( (NULL == daemon) ||
660 || (NULL == read_fd_set) 661 (NULL == read_fd_set) ||
661 || (NULL == write_fd_set) 662 (NULL == write_fd_set) ||
662 || (MHD_YES == daemon->shutdown) 663 (MHD_YES == daemon->shutdown) ||
663 || (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 664 (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) ||
664 || (0 != (daemon->options & MHD_USE_POLL))) 665 (0 != (daemon->options & MHD_USE_POLL)))
665 return MHD_NO; 666 return MHD_NO;
666#ifdef EPOLL_SUPPORT 667#ifdef EPOLL_SUPPORT
667 if (0 != (daemon->options & MHD_USE_EPOLL)) 668 if (0 != (daemon->options & MHD_USE_EPOLL))
@@ -669,11 +670,17 @@ MHD_get_fdset2 (struct MHD_Daemon *daemon,
669 /* we're in epoll mode, use the epoll FD as a stand-in for 670 /* we're in epoll mode, use the epoll FD as a stand-in for
670 the entire event set */ 671 the entire event set */
671 672
672 return MHD_add_to_fd_set_ (daemon->epoll_fd, read_fd_set, max_fd, fd_setsize) ? MHD_YES : MHD_NO; 673 return MHD_add_to_fd_set_ (daemon->epoll_fd,
674 read_fd_set,
675 max_fd,
676 fd_setsize) ? MHD_YES : MHD_NO;
673 } 677 }
674#endif 678#endif
675 if (MHD_INVALID_SOCKET != daemon->socket_fd && 679 if ( (MHD_INVALID_SOCKET != daemon->socket_fd) &&
676 !MHD_add_to_fd_set_ (daemon->socket_fd, read_fd_set, max_fd, fd_setsize)) 680 (! MHD_add_to_fd_set_ (daemon->socket_fd,
681 read_fd_set,
682 max_fd,
683 fd_setsize)) )
677 result = MHD_NO; 684 result = MHD_NO;
678 685
679 for (pos = daemon->connections_head; NULL != pos; pos = pos->next) 686 for (pos = daemon->connections_head; NULL != pos; pos = pos->next)
@@ -681,19 +688,31 @@ MHD_get_fdset2 (struct MHD_Daemon *daemon,
681 switch (pos->event_loop_info) 688 switch (pos->event_loop_info)
682 { 689 {
683 case MHD_EVENT_LOOP_INFO_READ: 690 case MHD_EVENT_LOOP_INFO_READ:
684 if (!MHD_add_to_fd_set_ (pos->socket_fd, read_fd_set, max_fd, fd_setsize)) 691 if (! MHD_add_to_fd_set_ (pos->socket_fd,
692 read_fd_set,
693 max_fd,
694 fd_setsize))
685 result = MHD_NO; 695 result = MHD_NO;
686 break; 696 break;
687 case MHD_EVENT_LOOP_INFO_WRITE: 697 case MHD_EVENT_LOOP_INFO_WRITE:
688 if (!MHD_add_to_fd_set_ (pos->socket_fd, write_fd_set, max_fd, fd_setsize)) 698 if (! MHD_add_to_fd_set_ (pos->socket_fd,
699 write_fd_set,
700 max_fd,
701 fd_setsize))
689 result = MHD_NO; 702 result = MHD_NO;
690 if (pos->read_buffer_size > pos->read_buffer_offset && 703 if ( (pos->read_buffer_size > pos->read_buffer_offset) &&
691 !MHD_add_to_fd_set_ (pos->socket_fd, read_fd_set, max_fd, fd_setsize)) 704 ! MHD_add_to_fd_set_ (pos->socket_fd,
705 read_fd_set,
706 max_fd,
707 fd_setsize))
692 result = MHD_NO; 708 result = MHD_NO;
693 break; 709 break;
694 case MHD_EVENT_LOOP_INFO_BLOCK: 710 case MHD_EVENT_LOOP_INFO_BLOCK:
695 if (pos->read_buffer_size > pos->read_buffer_offset && 711 if ( (pos->read_buffer_size > pos->read_buffer_offset) &&
696 !MHD_add_to_fd_set_ (pos->socket_fd, read_fd_set, max_fd, fd_setsize)) 712 ! MHD_add_to_fd_set_ (pos->socket_fd,
713 read_fd_set,
714 max_fd,
715 fd_setsize))
697 result = MHD_NO; 716 result = MHD_NO;
698 break; 717 break;
699 case MHD_EVENT_LOOP_INFO_CLEANUP: 718 case MHD_EVENT_LOOP_INFO_CLEANUP:
@@ -701,6 +720,33 @@ MHD_get_fdset2 (struct MHD_Daemon *daemon,
701 break; 720 break;
702 } 721 }
703 } 722 }
723 for (urh = daemon->urh_head; NULL != urh; urh = urh->next)
724 {
725 if ( (0 == (MHD_EPOLL_STATE_READ_READY & urh->celi_mhd)) &&
726 (! MHD_add_to_fd_set_ (urh->mhd_socket,
727 read_fd_set,
728 max_fd,
729 fd_setsize)) )
730 result = MHD_NO;
731 if ( (0 != (MHD_EPOLL_STATE_WRITE_READY & urh->celi_mhd)) &&
732 (! MHD_add_to_fd_set_ (urh->mhd_socket,
733 write_fd_set,
734 max_fd,
735 fd_setsize)) )
736 result = MHD_NO;
737 if ( (0 != (MHD_EPOLL_STATE_READ_READY & urh->celi_client)) &&
738 (! MHD_add_to_fd_set_ (urh->connection->socket_fd,
739 read_fd_set,
740 max_fd,
741 fd_setsize)) )
742 result = MHD_NO;
743 if ( (0 != (MHD_EPOLL_STATE_WRITE_READY & urh->celi_client)) &&
744 (! MHD_add_to_fd_set_ (urh->connection->socket_fd,
745 write_fd_set,
746 max_fd,
747 fd_setsize)) )
748 result = MHD_NO;
749 }
704#if DEBUG_CONNECT 750#if DEBUG_CONNECT
705#ifdef HAVE_MESSAGES 751#ifdef HAVE_MESSAGES
706 if (NULL != max_fd) 752 if (NULL != max_fd)
@@ -714,9 +760,8 @@ MHD_get_fdset2 (struct MHD_Daemon *daemon,
714 760
715 761
716/** 762/**
717 * Call the handlers for a connection in the 763 * Call the handlers for a connection in the appropriate order based
718 * appropriate order based on the readiness as 764 * on the readiness as detected by the event loop.
719 * detected by the event loop.
720 * 765 *
721 * @param con connection to handle 766 * @param con connection to handle
722 * @param read_ready set if the socket is ready for reading 767 * @param read_ready set if the socket is ready for reading
@@ -1239,7 +1284,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
1239 return MHD_NO; 1284 return MHD_NO;
1240 } 1285 }
1241 1286
1242 if ( (!MHD_SCKT_FD_FITS_FDSET_(client_socket, NULL)) && 1287 if ( (! MHD_SCKT_FD_FITS_FDSET_(client_socket, NULL)) &&
1243 (0 == (daemon->options & (MHD_USE_POLL | MHD_USE_EPOLL))) ) 1288 (0 == (daemon->options & (MHD_USE_POLL | MHD_USE_EPOLL))) )
1244 { 1289 {
1245#ifdef HAVE_MESSAGES 1290#ifdef HAVE_MESSAGES
@@ -1791,7 +1836,7 @@ MHD_add_connection (struct MHD_Daemon *daemon,
1791 already set in MHD_USE_EPOLL_TURBO mode */ 1836 already set in MHD_USE_EPOLL_TURBO mode */
1792 if (0 != (daemon->options & MHD_USE_EPOLL_TURBO)) 1837 if (0 != (daemon->options & MHD_USE_EPOLL_TURBO))
1793 { 1838 {
1794 if (!MHD_socket_nonblocking_ (client_socket)) 1839 if (! MHD_socket_nonblocking_ (client_socket))
1795 { 1840 {
1796#ifdef HAVE_MESSAGES 1841#ifdef HAVE_MESSAGES
1797 MHD_DLOG (daemon, 1842 MHD_DLOG (daemon,
@@ -1799,7 +1844,7 @@ MHD_add_connection (struct MHD_Daemon *daemon,
1799 MHD_socket_last_strerr_()); 1844 MHD_socket_last_strerr_());
1800#endif 1845#endif
1801 } 1846 }
1802 if (!MHD_socket_noninheritable_ (client_socket)) 1847 if (! MHD_socket_noninheritable_ (client_socket))
1803 { 1848 {
1804#ifdef HAVE_MESSAGES 1849#ifdef HAVE_MESSAGES
1805 MHD_DLOG (daemon, 1850 MHD_DLOG (daemon,
@@ -1858,7 +1903,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
1858 if (MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_(err)) 1903 if (MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_(err))
1859 return MHD_NO; /* do not print error if client just disconnected early */ 1904 return MHD_NO; /* do not print error if client just disconnected early */
1860#ifdef HAVE_MESSAGES 1905#ifdef HAVE_MESSAGES
1861 if ( !MHD_SCKT_ERR_IS_EAGAIN_ (err) ) 1906 if (! MHD_SCKT_ERR_IS_EAGAIN_ (err) )
1862 MHD_DLOG (daemon, 1907 MHD_DLOG (daemon,
1863 "Error accepting connection: %s\n", 1908 "Error accepting connection: %s\n",
1864 MHD_socket_strerr_(err)); 1909 MHD_socket_strerr_(err));
@@ -1895,7 +1940,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
1895 return MHD_NO; 1940 return MHD_NO;
1896 } 1941 }
1897#if !defined(USE_ACCEPT4) || !defined(HAVE_SOCK_NONBLOCK) 1942#if !defined(USE_ACCEPT4) || !defined(HAVE_SOCK_NONBLOCK)
1898 if (!MHD_socket_nonblocking_ (s)) 1943 if (! MHD_socket_nonblocking_ (s))
1899 { 1944 {
1900#ifdef HAVE_MESSAGES 1945#ifdef HAVE_MESSAGES
1901 MHD_DLOG (daemon, 1946 MHD_DLOG (daemon,
@@ -1905,7 +1950,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
1905 } 1950 }
1906#endif /* !USE_ACCEPT4 || !HAVE_SOCK_NONBLOCK */ 1951#endif /* !USE_ACCEPT4 || !HAVE_SOCK_NONBLOCK */
1907#if !defined(USE_ACCEPT4) || !defined(SOCK_CLOEXEC) 1952#if !defined(USE_ACCEPT4) || !defined(SOCK_CLOEXEC)
1908 if (!MHD_socket_noninheritable_ (s)) 1953 if (! MHD_socket_noninheritable_ (s))
1909 { 1954 {
1910#ifdef HAVE_MESSAGES 1955#ifdef HAVE_MESSAGES
1911 MHD_DLOG (daemon, 1956 MHD_DLOG (daemon,
@@ -1920,8 +1965,10 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
1920 s); 1965 s);
1921#endif 1966#endif
1922#endif 1967#endif
1923 (void) internal_add_connection (daemon, s, 1968 (void) internal_add_connection (daemon,
1924 addr, addrlen, 1969 s,
1970 addr,
1971 addrlen,
1925 MHD_NO); 1972 MHD_NO);
1926 return MHD_YES; 1973 return MHD_YES;
1927} 1974}