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.c36
1 files changed, 29 insertions, 7 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 1a47b972..7bbb2533 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -615,9 +615,12 @@ MHD_get_fdset (struct MHD_Daemon *daemon,
615 break; 615 break;
616 case MHD_EVENT_LOOP_INFO_WRITE: 616 case MHD_EVENT_LOOP_INFO_WRITE:
617 add_to_fd_set (pos->socket_fd, write_fd_set, max_fd); 617 add_to_fd_set (pos->socket_fd, write_fd_set, max_fd);
618 if (pos->read_buffer_size > pos->read_buffer_offset)
619 add_to_fd_set (pos->socket_fd, read_fd_set, max_fd);
618 break; 620 break;
619 case MHD_EVENT_LOOP_INFO_BLOCK: 621 case MHD_EVENT_LOOP_INFO_BLOCK:
620 /* not in any FD set */ 622 if (pos->read_buffer_size > pos->read_buffer_offset)
623 add_to_fd_set (pos->socket_fd, read_fd_set, max_fd);
621 break; 624 break;
622 case MHD_EVENT_LOOP_INFO_CLEANUP: 625 case MHD_EVENT_LOOP_INFO_CLEANUP:
623 /* this should never happen */ 626 /* this should never happen */
@@ -693,8 +696,12 @@ MHD_handle_connection (void *data)
693 break; 696 break;
694 case MHD_EVENT_LOOP_INFO_WRITE: 697 case MHD_EVENT_LOOP_INFO_WRITE:
695 add_to_fd_set (con->socket_fd, &ws, &max); 698 add_to_fd_set (con->socket_fd, &ws, &max);
699 if (con->read_buffer_size > con->read_buffer_offset)
700 add_to_fd_set (con->socket_fd, &rs, &max);
696 break; 701 break;
697 case MHD_EVENT_LOOP_INFO_BLOCK: 702 case MHD_EVENT_LOOP_INFO_BLOCK:
703 if (con->read_buffer_size > con->read_buffer_offset)
704 add_to_fd_set (con->socket_fd, &rs, &max);
698 tv.tv_sec = 0; 705 tv.tv_sec = 0;
699 tv.tv_usec = 0; 706 tv.tv_usec = 0;
700 tvp = &tv; 707 tvp = &tv;
@@ -741,8 +748,12 @@ MHD_handle_connection (void *data)
741 break; 748 break;
742 case MHD_EVENT_LOOP_INFO_WRITE: 749 case MHD_EVENT_LOOP_INFO_WRITE:
743 p[0].events |= POLLOUT; 750 p[0].events |= POLLOUT;
751 if (con->read_buffer_size > con->read_buffer_offset)
752 p[0].events |= POLLIN;
744 break; 753 break;
745 case MHD_EVENT_LOOP_INFO_BLOCK: 754 case MHD_EVENT_LOOP_INFO_BLOCK:
755 if (con->read_buffer_size > con->read_buffer_offset)
756 p[0].events |= POLLIN;
746 tv.tv_sec = 0; 757 tv.tv_sec = 0;
747 tv.tv_usec = 0; 758 tv.tv_usec = 0;
748 tvp = &tv; 759 tvp = &tv;
@@ -1774,11 +1785,16 @@ MHD_run_from_select (struct MHD_Daemon *daemon,
1774 pos->read_handler (pos); 1785 pos->read_handler (pos);
1775 break; 1786 break;
1776 case MHD_EVENT_LOOP_INFO_WRITE: 1787 case MHD_EVENT_LOOP_INFO_WRITE:
1788 if ( (FD_ISSET (ds, read_fd_set)) &&
1789 (pos->read_buffer_size > pos->read_buffer_offset) )
1790 pos->read_handler (pos);
1777 if (FD_ISSET (ds, write_fd_set)) 1791 if (FD_ISSET (ds, write_fd_set))
1778 pos->write_handler (pos); 1792 pos->write_handler (pos);
1779 break; 1793 break;
1780 case MHD_EVENT_LOOP_INFO_BLOCK: 1794 case MHD_EVENT_LOOP_INFO_BLOCK:
1781 /* only idle handler */ 1795 if ( (FD_ISSET (ds, read_fd_set)) &&
1796 (pos->read_buffer_size > pos->read_buffer_offset) )
1797 pos->read_handler (pos);
1782 break; 1798 break;
1783 case MHD_EVENT_LOOP_INFO_CLEANUP: 1799 case MHD_EVENT_LOOP_INFO_CLEANUP:
1784 /* should never happen */ 1800 /* should never happen */
@@ -1903,9 +1919,7 @@ MHD_poll_all (struct MHD_Daemon *daemon,
1903 /* count number of connections and thus determine poll set size */ 1919 /* count number of connections and thus determine poll set size */
1904 num_connections = 0; 1920 num_connections = 0;
1905 for (pos = daemon->connections_head; NULL != pos; pos = pos->next) 1921 for (pos = daemon->connections_head; NULL != pos; pos = pos->next)
1906 if ( (MHD_EVENT_LOOP_INFO_READ == pos->event_loop_info) || 1922 num_connections++;
1907 (MHD_EVENT_LOOP_INFO_WRITE == pos->event_loop_info) )
1908 num_connections++;
1909 { 1923 {
1910 struct pollfd p[2 + num_connections]; 1924 struct pollfd p[2 + num_connections];
1911 MHD_UNSIGNED_LONG_LONG ltimeout; 1925 MHD_UNSIGNED_LONG_LONG ltimeout;
@@ -1953,9 +1967,12 @@ MHD_poll_all (struct MHD_Daemon *daemon,
1953 break; 1967 break;
1954 case MHD_EVENT_LOOP_INFO_WRITE: 1968 case MHD_EVENT_LOOP_INFO_WRITE:
1955 p[poll_server+i].events |= POLLOUT; 1969 p[poll_server+i].events |= POLLOUT;
1970 if (pos->read_buffer_size > pos->read_buffer_offset)
1971 p[poll_server+i].events |= POLLIN;
1956 break; 1972 break;
1957 case MHD_EVENT_LOOP_INFO_BLOCK: 1973 case MHD_EVENT_LOOP_INFO_BLOCK:
1958 /* not in poll */ 1974 if (pos->read_buffer_size > pos->read_buffer_offset)
1975 p[poll_server+i].events |= POLLIN;
1959 break; 1976 break;
1960 case MHD_EVENT_LOOP_INFO_CLEANUP: 1977 case MHD_EVENT_LOOP_INFO_CLEANUP:
1961 /* should never happen */ 1978 /* should never happen */
@@ -2005,12 +2022,16 @@ MHD_poll_all (struct MHD_Daemon *daemon,
2005 if (p[poll_server+i].fd != pos->socket_fd) 2022 if (p[poll_server+i].fd != pos->socket_fd)
2006 break; /* fd mismatch, something else happened, retry later ... */ 2023 break; /* fd mismatch, something else happened, retry later ... */
2007 /* normal handling */ 2024 /* normal handling */
2025 if (0 != (p[poll_server+i].revents & POLLIN))
2026 pos->read_handler (pos);
2008 if (0 != (p[poll_server+i].revents & POLLOUT)) 2027 if (0 != (p[poll_server+i].revents & POLLOUT))
2009 pos->write_handler (pos); 2028 pos->write_handler (pos);
2010 pos->idle_handler (pos); 2029 pos->idle_handler (pos);
2011 i++; 2030 i++;
2012 break; 2031 break;
2013 case MHD_EVENT_LOOP_INFO_BLOCK: 2032 case MHD_EVENT_LOOP_INFO_BLOCK:
2033 if (0 != (p[poll_server+i].revents & POLLIN))
2034 pos->read_handler (pos);
2014 pos->idle_handler (pos); 2035 pos->idle_handler (pos);
2015 break; 2036 break;
2016 case MHD_EVENT_LOOP_INFO_CLEANUP: 2037 case MHD_EVENT_LOOP_INFO_CLEANUP:
@@ -2234,7 +2255,8 @@ MHD_epoll (struct MHD_Daemon *daemon,
2234 if (0 != (events[i].events & EPOLLIN)) 2255 if (0 != (events[i].events & EPOLLIN))
2235 { 2256 {
2236 pos->epoll_state |= MHD_EPOLL_STATE_READ_READY; 2257 pos->epoll_state |= MHD_EPOLL_STATE_READ_READY;
2237 if ( (MHD_EVENT_LOOP_INFO_READ == pos->event_loop_info) && 2258 if ( ( (MHD_EVENT_LOOP_INFO_READ == pos->event_loop_info) ||
2259 (pos->read_buffer_size > pos->read_buffer_offset) ) &&
2238 (0 == (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL) ) ) 2260 (0 == (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL) ) )
2239 { 2261 {
2240 EDLL_insert (daemon->eready_head, 2262 EDLL_insert (daemon->eready_head,