aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2017-02-21 21:34:39 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2017-02-21 21:34:39 +0300
commit813fc203ef95f7e3b1d410e182d363a30f5fdad3 (patch)
tree44d8ab30b40c92e21136d13e68d96eaf86d933fd /src/microhttpd
parent0e0822dd3e6e7b3c3a1ff1f2501fe40481932429 (diff)
downloadlibmicrohttpd-813fc203ef95f7e3b1d410e182d363a30f5fdad3.tar.gz
libmicrohttpd-813fc203ef95f7e3b1d410e182d363a30f5fdad3.zip
call_handlers(): always call idle_handler() after each read/write. This allow to process both
read and write at single call_handlers() invocation if readability and writeability are both known (epoll mode). Simplified checks for 'fast track' mode.
Diffstat (limited to 'src/microhttpd')
-rw-r--r--src/microhttpd/daemon.c56
1 files changed, 33 insertions, 23 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index fcd70ce1..f983e916 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -886,8 +886,8 @@ call_handlers (struct MHD_Connection *con,
886 bool force_close) 886 bool force_close)
887{ 887{
888 int ret; 888 int ret;
889 /* Initial state of connection. */ 889 /* Fast track flag */
890 bool was_initing = (con->state == MHD_CONNECTION_INIT); 890 bool on_fasttrack = (con->state == MHD_CONNECTION_INIT);
891 891
892#ifdef HTTPS_SUPPORT 892#ifdef HTTPS_SUPPORT
893 if (con->tls_read_ready) 893 if (con->tls_read_ready)
@@ -896,15 +896,24 @@ call_handlers (struct MHD_Connection *con,
896 if (!force_close) 896 if (!force_close)
897 { 897 {
898 if (MHD_EVENT_LOOP_INFO_READ == con->event_loop_info && read_ready) 898 if (MHD_EVENT_LOOP_INFO_READ == con->event_loop_info && read_ready)
899 con->read_handler (con); 899 {
900 con->read_handler (con);
901 ret = con->idle_handler (con);
902 }
903 /* No need to check value of 'ret' here as closed connection
904 * cannot be in MHD_EVENT_LOOP_INFO_WRITE state. */
900 if (MHD_EVENT_LOOP_INFO_WRITE == con->event_loop_info && write_ready) 905 if (MHD_EVENT_LOOP_INFO_WRITE == con->event_loop_info && write_ready)
901 con->write_handler (con); 906 {
907 con->write_handler (con);
908 ret = con->idle_handler (con);
909 }
902 } 910 }
903 else 911 else
904 MHD_connection_close_ (con, 912 {
905 MHD_REQUEST_TERMINATED_WITH_ERROR); 913 MHD_connection_close_ (con,
906 914 MHD_REQUEST_TERMINATED_WITH_ERROR);
907 ret = con->idle_handler (con); 915 return con->idle_handler (con);
916 }
908 917
909 /* Fast track for fast connections. */ 918 /* Fast track for fast connections. */
910 /* If full request was read by single read_handler() invocation 919 /* If full request was read by single read_handler() invocation
@@ -914,23 +923,24 @@ call_handlers (struct MHD_Connection *con,
914 As writeability of socket was not checked and it may have 923 As writeability of socket was not checked and it may have
915 some data pending in system buffers, use this optimization 924 some data pending in system buffers, use this optimization
916 only for non-blocking sockets. */ 925 only for non-blocking sockets. */
917 if ( (MHD_NO != ret) && 926 /* No need to check 'ret' as connection is always in
918 (was_initing) && 927 * MHD_CONNECTION_CLOSED state if 'ret' is equal 'MHD_NO'. */
919 (MHD_CONNECTION_HEADERS_SENDING == con->state) && 928 if (on_fasttrack && con->sk_nonblck)
920 (con->sk_nonblck) ) 929 {
921 { 930 if (MHD_CONNECTION_HEADERS_SENDING == con->state)
922 con->write_handler (con);
923 /* If all headers were sent by single write_handler() - continue. */
924 if (MHD_CONNECTION_HEADERS_SENT == con->state)
925 { 931 {
932 con->write_handler (con);
933 /* Always call 'idle_handler()' after each read/write. */
934 ret = con->idle_handler (con);
935 }
936 /* If all headers were sent by single write_handler() and
937 * response body is prepared by single idle_handler()
938 * call - continue. */
939 if ((MHD_CONNECTION_NORMAL_BODY_READY == con->state) ||
940 (MHD_CONNECTION_CHUNKED_BODY_READY == con->state))
941 {
942 con->write_handler (con);
926 ret = con->idle_handler (con); 943 ret = con->idle_handler (con);
927 if ( (MHD_NO != ret) &&
928 ( (MHD_CONNECTION_NORMAL_BODY_READY == con->state) ||
929 (MHD_CONNECTION_CHUNKED_BODY_READY == con->state) ) )
930 {
931 con->write_handler (con);
932 ret = con->idle_handler (con);
933 }
934 } 944 }
935 } 945 }
936 return ret; 946 return ret;