diff options
-rw-r--r-- | src/gnutls/update_event_loop_info.c | 20 | ||||
-rw-r--r-- | src/include/microhttpd2.h | 39 | ||||
-rw-r--r-- | src/include/microhttpd_tls.h | 33 | ||||
-rw-r--r-- | src/lib/Makefile.am | 1 | ||||
-rw-r--r-- | src/lib/action_from_response.c | 2 | ||||
-rw-r--r-- | src/lib/connection_call_handlers.c | 167 | ||||
-rw-r--r-- | src/lib/connection_update_event_loop_info.c | 195 | ||||
-rw-r--r-- | src/lib/connection_update_event_loop_info.h | 42 | ||||
-rw-r--r-- | src/lib/daemon_epoll.c | 6 | ||||
-rw-r--r-- | src/lib/internal.h | 27 |
10 files changed, 259 insertions, 273 deletions
diff --git a/src/gnutls/update_event_loop_info.c b/src/gnutls/update_event_loop_info.c new file mode 100644 index 00000000..327b20e4 --- /dev/null +++ b/src/gnutls/update_event_loop_info.c | |||
@@ -0,0 +1,20 @@ | |||
1 | enum MHD_Bool | ||
2 | (*update_event_loop_info)(void *cls, | ||
3 | struct MHD_TLS_ConnectionState *cs, | ||
4 | enum MHD_RequestEventLoopInfo *eli); | ||
5 | |||
6 | |||
7 | switch (connection->tls_state) | ||
8 | { | ||
9 | case MHD_TLS_CONN_INIT: | ||
10 | *eli = MHD_EVENT_LOOP_INFO_READ; | ||
11 | return true; | ||
12 | case MHD_TLS_CONN_HANDSHAKING: | ||
13 | if (0 == gnutls_record_get_direction (connection->tls_session)) | ||
14 | *eli = MHD_EVENT_LOOP_INFO_READ; | ||
15 | else | ||
16 | *eli = MHD_EVENT_LOOP_INFO_WRITE; | ||
17 | return true; | ||
18 | default: | ||
19 | return false; | ||
20 | } | ||
diff --git a/src/include/microhttpd2.h b/src/include/microhttpd2.h index 05fa58e9..a3494aeb 100644 --- a/src/include/microhttpd2.h +++ b/src/include/microhttpd2.h | |||
@@ -323,12 +323,13 @@ struct MHD_Connection; | |||
323 | * for logging. | 323 | * for logging. |
324 | * | 324 | * |
325 | * A value of 0 indicates success (as a return value). | 325 | * A value of 0 indicates success (as a return value). |
326 | * Values between 1 and 10000 must not be used. | 326 | * Values between 0 and 10000 must be handled explicitly by the app. |
327 | * Values from 10000-19999 are informational. | 327 | * Values from 10000-19999 are informational. |
328 | * Values from 20000-29999 indicate successful operations. | 328 | * Values from 20000-29999 indicate successful operations. |
329 | * Values from 30000-39999 indicate unsuccessful (normal) operations. | 329 | * Values from 30000-39999 indicate unsuccessful (normal) operations. |
330 | * Values from 40000-49999 indicate client errors. | 330 | * Values from 40000-49999 indicate client errors. |
331 | * Values from 50000-59999 indicate server errors. | 331 | * Values from 50000-59999 indicate MHD server errors. |
332 | * Values from 60000-69999 indicate application errors. | ||
332 | */ | 333 | */ |
333 | enum MHD_StatusCode | 334 | enum MHD_StatusCode |
334 | { | 335 | { |
@@ -866,6 +867,13 @@ enum MHD_StatusCode | |||
866 | */ | 867 | */ |
867 | MHD_SC_APPLICATION_HUNG_CONNECTION = 60007, | 868 | MHD_SC_APPLICATION_HUNG_CONNECTION = 60007, |
868 | 869 | ||
870 | /** | ||
871 | * Application only partially processed upload and did | ||
872 | * not suspend connection and the read buffer was maxxed | ||
873 | * out, so MHD closed the connection. | ||
874 | */ | ||
875 | MHD_SC_APPLICATION_HUNG_CONNECTION_CLOSED = 60008, | ||
876 | |||
869 | 877 | ||
870 | }; | 878 | }; |
871 | 879 | ||
@@ -4154,4 +4162,31 @@ _MHD_EXTERN enum MHD_Bool | |||
4154 | MHD_is_feature_supported (enum MHD_Feature feature); | 4162 | MHD_is_feature_supported (enum MHD_Feature feature); |
4155 | 4163 | ||
4156 | 4164 | ||
4165 | /** | ||
4166 | * What is this request waiting for? | ||
4167 | */ | ||
4168 | enum MHD_RequestEventLoopInfo | ||
4169 | { | ||
4170 | /** | ||
4171 | * We are waiting to be able to read. | ||
4172 | */ | ||
4173 | MHD_EVENT_LOOP_INFO_READ = 0, | ||
4174 | |||
4175 | /** | ||
4176 | * We are waiting to be able to write. | ||
4177 | */ | ||
4178 | MHD_EVENT_LOOP_INFO_WRITE = 1, | ||
4179 | |||
4180 | /** | ||
4181 | * We are waiting for the application to provide data. | ||
4182 | */ | ||
4183 | MHD_EVENT_LOOP_INFO_BLOCK = 2, | ||
4184 | |||
4185 | /** | ||
4186 | * We are finished and are awaiting cleanup. | ||
4187 | */ | ||
4188 | MHD_EVENT_LOOP_INFO_CLEANUP = 3 | ||
4189 | }; | ||
4190 | |||
4191 | |||
4157 | #endif | 4192 | #endif |
diff --git a/src/include/microhttpd_tls.h b/src/include/microhttpd_tls.h index 85862a45..f5b48522 100644 --- a/src/include/microhttpd_tls.h +++ b/src/include/microhttpd_tls.h | |||
@@ -1,6 +1,33 @@ | |||
1 | /* | ||
2 | This file is part of libmicrohttpd | ||
3 | Copyright (C) 2018 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | */ | ||
19 | |||
20 | /** | ||
21 | * @file microhttpd_tls.h | ||
22 | * @brief interface for TLS plugins of libmicrohttpd | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
25 | |||
1 | #ifndef MICROHTTPD_TLS_H | 26 | #ifndef MICROHTTPD_TLS_H |
2 | #define MICROHTTPD_TLS_H | 27 | #define MICROHTTPD_TLS_H |
3 | 28 | ||
29 | #include <microhttpd2.h> | ||
30 | |||
4 | /** | 31 | /** |
5 | * Version of the TLS ABI. | 32 | * Version of the TLS ABI. |
6 | */ | 33 | */ |
@@ -100,6 +127,12 @@ struct MHD_TLS_Plugin | |||
100 | enum MHD_Bool | 127 | enum MHD_Bool |
101 | (*idle_ready)(void *cls, | 128 | (*idle_ready)(void *cls, |
102 | struct MHD_TLS_ConnectionState *cs); | 129 | struct MHD_TLS_ConnectionState *cs); |
130 | |||
131 | |||
132 | enum MHD_Bool | ||
133 | (*update_event_loop_info)(void *cls, | ||
134 | struct MHD_TLS_ConnectionState *cs, | ||
135 | enum MHD_RequestEventLoopInfo *eli); | ||
103 | 136 | ||
104 | ssize_t | 137 | ssize_t |
105 | (*send)(void *cls, | 138 | (*send)(void *cls, |
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 9f432417..320287d3 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am | |||
@@ -65,7 +65,6 @@ libmicrohttpd_la_SOURCES = \ | |||
65 | connection_finish_forward.c connection_finish_forward.h \ | 65 | connection_finish_forward.c connection_finish_forward.h \ |
66 | connection_info.c \ | 66 | connection_info.c \ |
67 | connection_options.c \ | 67 | connection_options.c \ |
68 | connection_update_event_loop_info.c connection_update_event_loop_info.h \ | ||
69 | connection_update_last_activity.c connection_update_last_activity.h \ | 68 | connection_update_last_activity.c connection_update_last_activity.h \ |
70 | daemon_close_all_connections.c daemon_close_all_connections.h \ | 69 | daemon_close_all_connections.c daemon_close_all_connections.h \ |
71 | daemon_create.c \ | 70 | daemon_create.c \ |
diff --git a/src/lib/action_from_response.c b/src/lib/action_from_response.c index d3dccc5f..007363fb 100644 --- a/src/lib/action_from_response.c +++ b/src/lib/action_from_response.c | |||
@@ -89,7 +89,7 @@ response_action (void *cls, | |||
89 | request->state = MHD_REQUEST_FOOTERS_RECEIVED; | 89 | request->state = MHD_REQUEST_FOOTERS_RECEIVED; |
90 | } | 90 | } |
91 | if (! request->in_idle) | 91 | if (! request->in_idle) |
92 | (void) MHD_connection_handle_idle (request->connection); | 92 | (void) MHD_request_handle_idle_ (request); |
93 | return MHD_SC_OK; | 93 | return MHD_SC_OK; |
94 | } | 94 | } |
95 | 95 | ||
diff --git a/src/lib/connection_call_handlers.c b/src/lib/connection_call_handlers.c index bb6123eb..bc64da30 100644 --- a/src/lib/connection_call_handlers.c +++ b/src/lib/connection_call_handlers.c | |||
@@ -23,7 +23,6 @@ | |||
23 | */ | 23 | */ |
24 | #include "internal.h" | 24 | #include "internal.h" |
25 | #include "connection_call_handlers.h" | 25 | #include "connection_call_handlers.h" |
26 | #include "connection_update_event_loop_info.h" | ||
27 | #include "connection_update_last_activity.h" | 26 | #include "connection_update_last_activity.h" |
28 | #include "connection_close.h" | 27 | #include "connection_close.h" |
29 | 28 | ||
@@ -2889,6 +2888,170 @@ connection_epoll_update_ (struct MHD_Connection *connection) | |||
2889 | 2888 | ||
2890 | 2889 | ||
2891 | /** | 2890 | /** |
2891 | * Update the 'event_loop_info' field of this connection based on the | ||
2892 | * state that the connection is now in. May also close the connection | ||
2893 | * or perform other updates to the connection if needed to prepare for | ||
2894 | * the next round of the event loop. | ||
2895 | * | ||
2896 | * @param connection connection to get poll set for | ||
2897 | */ | ||
2898 | static void | ||
2899 | connection_update_event_loop_info (struct MHD_Connection *connection) | ||
2900 | { | ||
2901 | struct MHD_Daemon *daemon = connection->daemon; | ||
2902 | struct MHD_Request *request = &connection->request; | ||
2903 | |||
2904 | /* Do not update states of suspended connection */ | ||
2905 | if (connection->suspended) | ||
2906 | return; /* States will be updated after resume. */ | ||
2907 | #ifdef HTTPS_SUPPORT | ||
2908 | { | ||
2909 | struct MHD_TLS_Plugin *tls; | ||
2910 | |||
2911 | if ( (NULL != (tls = daemon->tls_api)) && | ||
2912 | (tls->update_event_loop_info (tls->cls, | ||
2913 | connection->tls_cs, | ||
2914 | &request->event_loop_info)) ) | ||
2915 | return; /* TLS has decided what to do */ | ||
2916 | } | ||
2917 | #endif /* HTTPS_SUPPORT */ | ||
2918 | while (1) | ||
2919 | { | ||
2920 | #if DEBUG_STATES | ||
2921 | MHD_DLOG (daemon, | ||
2922 | MHD_SC_STATE_MACHINE_STATUS_REPORT, | ||
2923 | _("In function %s handling connection at state: %s\n"), | ||
2924 | __FUNCTION__, | ||
2925 | MHD_state_to_string (request->state)); | ||
2926 | #endif | ||
2927 | switch (request->state) | ||
2928 | { | ||
2929 | case MHD_REQUEST_INIT: | ||
2930 | case MHD_REQUEST_URL_RECEIVED: | ||
2931 | case MHD_REQUEST_HEADER_PART_RECEIVED: | ||
2932 | /* while reading headers, we always grow the | ||
2933 | read buffer if needed, no size-check required */ | ||
2934 | if ( (request->read_buffer_offset == request->read_buffer_size) && | ||
2935 | (! try_grow_read_buffer (request)) ) | ||
2936 | { | ||
2937 | transmit_error_response (request, | ||
2938 | MHD_SC_CLIENT_HEADER_TOO_BIG, | ||
2939 | (NULL != request->url) | ||
2940 | ? MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE | ||
2941 | : MHD_HTTP_URI_TOO_LONG, | ||
2942 | REQUEST_TOO_BIG); | ||
2943 | continue; | ||
2944 | } | ||
2945 | if (! connection->read_closed) | ||
2946 | request->event_loop_info = MHD_EVENT_LOOP_INFO_READ; | ||
2947 | else | ||
2948 | request->event_loop_info = MHD_EVENT_LOOP_INFO_BLOCK; | ||
2949 | break; | ||
2950 | case MHD_REQUEST_HEADERS_RECEIVED: | ||
2951 | mhd_assert (0); | ||
2952 | break; | ||
2953 | case MHD_REQUEST_HEADERS_PROCESSED: | ||
2954 | mhd_assert (0); | ||
2955 | break; | ||
2956 | case MHD_REQUEST_CONTINUE_SENDING: | ||
2957 | request->event_loop_info = MHD_EVENT_LOOP_INFO_WRITE; | ||
2958 | break; | ||
2959 | case MHD_REQUEST_CONTINUE_SENT: | ||
2960 | if (request->read_buffer_offset == request->read_buffer_size) | ||
2961 | { | ||
2962 | if ( (! try_grow_read_buffer (request)) && | ||
2963 | (MHD_TM_EXTERNAL_EVENT_LOOP != daemon->threading_model) ) | ||
2964 | { | ||
2965 | /* failed to grow the read buffer, and the client | ||
2966 | which is supposed to handle the received data in | ||
2967 | a *blocking* fashion (in this mode) did not | ||
2968 | handle the data as it was supposed to! | ||
2969 | |||
2970 | => we would either have to do busy-waiting | ||
2971 | (on the client, which would likely fail), | ||
2972 | or if we do nothing, we would just timeout | ||
2973 | on the connection (if a timeout is even set!). | ||
2974 | |||
2975 | Solution: we kill the connection with an error */ | ||
2976 | transmit_error_response (request, | ||
2977 | MHD_SC_APPLICATION_HUNG_CONNECTION_CLOSED, | ||
2978 | MHD_HTTP_INTERNAL_SERVER_ERROR, | ||
2979 | INTERNAL_ERROR); | ||
2980 | continue; | ||
2981 | } | ||
2982 | } | ||
2983 | if ( (request->read_buffer_offset < request->read_buffer_size) && | ||
2984 | (! connection->read_closed) ) | ||
2985 | request->event_loop_info = MHD_EVENT_LOOP_INFO_READ; | ||
2986 | else | ||
2987 | request->event_loop_info = MHD_EVENT_LOOP_INFO_BLOCK; | ||
2988 | break; | ||
2989 | case MHD_REQUEST_BODY_RECEIVED: | ||
2990 | case MHD_REQUEST_FOOTER_PART_RECEIVED: | ||
2991 | /* while reading footers, we always grow the | ||
2992 | read buffer if needed, no size-check required */ | ||
2993 | if (connection->read_closed) | ||
2994 | { | ||
2995 | CONNECTION_CLOSE_ERROR (connection, | ||
2996 | MHD_SC_CONNECTION_READ_FAIL_CLOSED, | ||
2997 | NULL); | ||
2998 | continue; | ||
2999 | } | ||
3000 | request->event_loop_info = MHD_EVENT_LOOP_INFO_READ; | ||
3001 | /* transition to FOOTERS_RECEIVED | ||
3002 | happens in read handler */ | ||
3003 | break; | ||
3004 | case MHD_REQUEST_FOOTERS_RECEIVED: | ||
3005 | request->event_loop_info = MHD_EVENT_LOOP_INFO_BLOCK; | ||
3006 | break; | ||
3007 | case MHD_REQUEST_HEADERS_SENDING: | ||
3008 | /* headers in buffer, keep writing */ | ||
3009 | request->event_loop_info = MHD_EVENT_LOOP_INFO_WRITE; | ||
3010 | break; | ||
3011 | case MHD_REQUEST_HEADERS_SENT: | ||
3012 | mhd_assert (0); | ||
3013 | break; | ||
3014 | case MHD_REQUEST_NORMAL_BODY_READY: | ||
3015 | request->event_loop_info = MHD_EVENT_LOOP_INFO_WRITE; | ||
3016 | break; | ||
3017 | case MHD_REQUEST_NORMAL_BODY_UNREADY: | ||
3018 | request->event_loop_info = MHD_EVENT_LOOP_INFO_BLOCK; | ||
3019 | break; | ||
3020 | case MHD_REQUEST_CHUNKED_BODY_READY: | ||
3021 | request->event_loop_info = MHD_EVENT_LOOP_INFO_WRITE; | ||
3022 | break; | ||
3023 | case MHD_REQUEST_CHUNKED_BODY_UNREADY: | ||
3024 | request->event_loop_info = MHD_EVENT_LOOP_INFO_BLOCK; | ||
3025 | break; | ||
3026 | case MHD_REQUEST_BODY_SENT: | ||
3027 | mhd_assert (0); | ||
3028 | break; | ||
3029 | case MHD_REQUEST_FOOTERS_SENDING: | ||
3030 | request->event_loop_info = MHD_EVENT_LOOP_INFO_WRITE; | ||
3031 | break; | ||
3032 | case MHD_REQUEST_FOOTERS_SENT: | ||
3033 | mhd_assert (0); | ||
3034 | break; | ||
3035 | case MHD_REQUEST_CLOSED: | ||
3036 | request->event_loop_info = MHD_EVENT_LOOP_INFO_CLEANUP; | ||
3037 | return; /* do nothing, not even reading */ | ||
3038 | case MHD_REQUEST_IN_CLEANUP: | ||
3039 | mhd_assert (0); | ||
3040 | break; | ||
3041 | #ifdef UPGRADE_SUPPORT | ||
3042 | case MHD_REQUEST_UPGRADE: | ||
3043 | mhd_assert (0); | ||
3044 | break; | ||
3045 | #endif /* UPGRADE_SUPPORT */ | ||
3046 | default: | ||
3047 | mhd_assert (0); | ||
3048 | } | ||
3049 | break; | ||
3050 | } | ||
3051 | } | ||
3052 | |||
3053 | |||
3054 | /** | ||
2892 | * This function was created to handle per-request processing that | 3055 | * This function was created to handle per-request processing that |
2893 | * has to happen even if the socket cannot be read or written to. | 3056 | * has to happen even if the socket cannot be read or written to. |
2894 | * @remark To be called only from thread that process request's | 3057 | * @remark To be called only from thread that process request's |
@@ -3386,7 +3549,7 @@ MHD_request_handle_idle_ (struct MHD_Request *request) | |||
3386 | return true; | 3549 | return true; |
3387 | } | 3550 | } |
3388 | } | 3551 | } |
3389 | MHD_connection_update_event_loop_info_ (connection); | 3552 | connection_update_event_loop_info (connection); |
3390 | ret = true; | 3553 | ret = true; |
3391 | #ifdef EPOLL_SUPPORT | 3554 | #ifdef EPOLL_SUPPORT |
3392 | if ( (! connection->suspended) && | 3555 | if ( (! connection->suspended) && |
diff --git a/src/lib/connection_update_event_loop_info.c b/src/lib/connection_update_event_loop_info.c deleted file mode 100644 index 1504d545..00000000 --- a/src/lib/connection_update_event_loop_info.c +++ /dev/null | |||
@@ -1,195 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of libmicrohttpd | ||
3 | Copyright (C) 2007-2018 Daniel Pittman and Christian Grothoff | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | */ | ||
19 | /** | ||
20 | * @file lib/connection_update_event_loop_info.c | ||
21 | * @brief update the set of network events this connection is waiting for | ||
22 | * @author Christian Grothoff | ||
23 | */ | ||
24 | #include "internal.h" | ||
25 | #include "connection_update_event_loop_info.h" | ||
26 | |||
27 | |||
28 | /** | ||
29 | * Update the 'event_loop_info' field of this connection based on the | ||
30 | * state that the connection is now in. May also close the connection | ||
31 | * or perform other updates to the connection if needed to prepare for | ||
32 | * the next round of the event loop. | ||
33 | * | ||
34 | * @param connection connection to get poll set for | ||
35 | */ | ||
36 | void | ||
37 | MHD_connection_update_event_loop_info_ (struct MHD_Connection *connection) | ||
38 | { | ||
39 | /* Do not update states of suspended connection */ | ||
40 | if (connection->suspended) | ||
41 | return; /* States will be updated after resume. */ | ||
42 | #ifdef HTTPS_SUPPORT | ||
43 | if (MHD_TLS_CONN_NO_TLS != connection->tls_state) | ||
44 | { /* HTTPS connection. */ | ||
45 | switch (connection->tls_state) | ||
46 | { | ||
47 | case MHD_TLS_CONN_INIT: | ||
48 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_READ; | ||
49 | return; | ||
50 | case MHD_TLS_CONN_HANDSHAKING: | ||
51 | if (0 == gnutls_record_get_direction (connection->tls_session)) | ||
52 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_READ; | ||
53 | else | ||
54 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_WRITE; | ||
55 | return; | ||
56 | default: | ||
57 | break; | ||
58 | } | ||
59 | } | ||
60 | #endif /* HTTPS_SUPPORT */ | ||
61 | while (1) | ||
62 | { | ||
63 | #if DEBUG_STATES | ||
64 | MHD_DLOG (connection->daemon, | ||
65 | _("In function %s handling connection at state: %s\n"), | ||
66 | __FUNCTION__, | ||
67 | MHD_state_to_string (connection->state)); | ||
68 | #endif | ||
69 | switch (connection->state) | ||
70 | { | ||
71 | case MHD_CONNECTION_INIT: | ||
72 | case MHD_CONNECTION_URL_RECEIVED: | ||
73 | case MHD_CONNECTION_HEADER_PART_RECEIVED: | ||
74 | /* while reading headers, we always grow the | ||
75 | read buffer if needed, no size-check required */ | ||
76 | if ( (connection->read_buffer_offset == connection->read_buffer_size) && | ||
77 | (MHD_NO == try_grow_read_buffer (connection)) ) | ||
78 | { | ||
79 | transmit_error_response (connection, | ||
80 | (connection->url != NULL) | ||
81 | ? MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE | ||
82 | : MHD_HTTP_URI_TOO_LONG, | ||
83 | REQUEST_TOO_BIG); | ||
84 | continue; | ||
85 | } | ||
86 | if (! connection->read_closed) | ||
87 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_READ; | ||
88 | else | ||
89 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_BLOCK; | ||
90 | break; | ||
91 | case MHD_CONNECTION_HEADERS_RECEIVED: | ||
92 | mhd_assert (0); | ||
93 | break; | ||
94 | case MHD_CONNECTION_HEADERS_PROCESSED: | ||
95 | mhd_assert (0); | ||
96 | break; | ||
97 | case MHD_CONNECTION_CONTINUE_SENDING: | ||
98 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_WRITE; | ||
99 | break; | ||
100 | case MHD_CONNECTION_CONTINUE_SENT: | ||
101 | if (connection->read_buffer_offset == connection->read_buffer_size) | ||
102 | { | ||
103 | if ((MHD_YES != try_grow_read_buffer (connection)) && | ||
104 | (0 != (connection->daemon->options & | ||
105 | MHD_USE_INTERNAL_POLLING_THREAD))) | ||
106 | { | ||
107 | /* failed to grow the read buffer, and the | ||
108 | client which is supposed to handle the | ||
109 | received data in a *blocking* fashion | ||
110 | (in this mode) did not handle the data as | ||
111 | it was supposed to! | ||
112 | => we would either have to do busy-waiting | ||
113 | (on the client, which would likely fail), | ||
114 | or if we do nothing, we would just timeout | ||
115 | on the connection (if a timeout is even | ||
116 | set!). | ||
117 | Solution: we kill the connection with an error */ | ||
118 | transmit_error_response (connection, | ||
119 | MHD_HTTP_INTERNAL_SERVER_ERROR, | ||
120 | INTERNAL_ERROR); | ||
121 | continue; | ||
122 | } | ||
123 | } | ||
124 | if ( (connection->read_buffer_offset < connection->read_buffer_size) && | ||
125 | (! connection->read_closed) ) | ||
126 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_READ; | ||
127 | else | ||
128 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_BLOCK; | ||
129 | break; | ||
130 | case MHD_CONNECTION_BODY_RECEIVED: | ||
131 | case MHD_CONNECTION_FOOTER_PART_RECEIVED: | ||
132 | /* while reading footers, we always grow the | ||
133 | read buffer if needed, no size-check required */ | ||
134 | if (connection->read_closed) | ||
135 | { | ||
136 | CONNECTION_CLOSE_ERROR (connection, | ||
137 | NULL); | ||
138 | continue; | ||
139 | } | ||
140 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_READ; | ||
141 | /* transition to FOOTERS_RECEIVED | ||
142 | happens in read handler */ | ||
143 | break; | ||
144 | case MHD_CONNECTION_FOOTERS_RECEIVED: | ||
145 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_BLOCK; | ||
146 | break; | ||
147 | case MHD_CONNECTION_HEADERS_SENDING: | ||
148 | /* headers in buffer, keep writing */ | ||
149 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_WRITE; | ||
150 | break; | ||
151 | case MHD_CONNECTION_HEADERS_SENT: | ||
152 | mhd_assert (0); | ||
153 | break; | ||
154 | case MHD_CONNECTION_NORMAL_BODY_READY: | ||
155 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_WRITE; | ||
156 | break; | ||
157 | case MHD_CONNECTION_NORMAL_BODY_UNREADY: | ||
158 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_BLOCK; | ||
159 | break; | ||
160 | case MHD_CONNECTION_CHUNKED_BODY_READY: | ||
161 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_WRITE; | ||
162 | break; | ||
163 | case MHD_CONNECTION_CHUNKED_BODY_UNREADY: | ||
164 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_BLOCK; | ||
165 | break; | ||
166 | case MHD_CONNECTION_BODY_SENT: | ||
167 | mhd_assert (0); | ||
168 | break; | ||
169 | case MHD_CONNECTION_FOOTERS_SENDING: | ||
170 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_WRITE; | ||
171 | break; | ||
172 | case MHD_CONNECTION_FOOTERS_SENT: | ||
173 | mhd_assert (0); | ||
174 | break; | ||
175 | case MHD_CONNECTION_CLOSED: | ||
176 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_CLEANUP; | ||
177 | return; /* do nothing, not even reading */ | ||
178 | case MHD_CONNECTION_IN_CLEANUP: | ||
179 | mhd_assert (0); | ||
180 | break; | ||
181 | #ifdef UPGRADE_SUPPORT | ||
182 | case MHD_CONNECTION_UPGRADE: | ||
183 | mhd_assert (0); | ||
184 | break; | ||
185 | #endif /* UPGRADE_SUPPORT */ | ||
186 | default: | ||
187 | mhd_assert (0); | ||
188 | } | ||
189 | break; | ||
190 | } | ||
191 | } | ||
192 | |||
193 | |||
194 | /* end of connection_update_event_loop_info.c */ | ||
195 | |||
diff --git a/src/lib/connection_update_event_loop_info.h b/src/lib/connection_update_event_loop_info.h deleted file mode 100644 index 005e03a8..00000000 --- a/src/lib/connection_update_event_loop_info.h +++ /dev/null | |||
@@ -1,42 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of libmicrohttpd | ||
3 | Copyright (C) 2007-2018 Daniel Pittman and Christian Grothoff | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | */ | ||
19 | /** | ||
20 | * @file lib/connection_update_event_loop_info.h | ||
21 | * @brief function to update last activity of a connection | ||
22 | * @author Christian Grothoff | ||
23 | */ | ||
24 | |||
25 | #ifndef CONNECTION_UPDATE_EVENT_LOOP_INFO_H | ||
26 | #define CONNECTION_UPDATE_EVENT_LOOP_INFO_H | ||
27 | |||
28 | |||
29 | /** | ||
30 | * Update the 'event_loop_info' field of this connection based on the | ||
31 | * state that the connection is now in. May also close the connection | ||
32 | * or perform other updates to the connection if needed to prepare for | ||
33 | * the next round of the event loop. | ||
34 | * | ||
35 | * @param connection connection to get poll set for | ||
36 | */ | ||
37 | void | ||
38 | MHD_connection_update_event_loop_info_ (struct MHD_Connection *connection) | ||
39 | MHD_NONNULL (1); | ||
40 | |||
41 | |||
42 | #endif | ||
diff --git a/src/lib/daemon_epoll.c b/src/lib/daemon_epoll.c index 74d44523..4bed148f 100644 --- a/src/lib/daemon_epoll.c +++ b/src/lib/daemon_epoll.c | |||
@@ -477,7 +477,7 @@ MHD_daemon_epoll_ (struct MHD_Daemon *daemon, | |||
477 | } | 477 | } |
478 | 478 | ||
479 | /* Finally, handle timed-out connections; we need to do this here | 479 | /* Finally, handle timed-out connections; we need to do this here |
480 | as the epoll mechanism won't call the 'MHD_connection_handle_idle()' on everything, | 480 | as the epoll mechanism won't call the 'MHD_request_handle_idle_()' on everything, |
481 | as the other event loops do. As timeouts do not get an explicit | 481 | as the other event loops do. As timeouts do not get an explicit |
482 | event, we need to find those connections that might have timed out | 482 | event, we need to find those connections that might have timed out |
483 | here. | 483 | here. |
@@ -488,7 +488,7 @@ MHD_daemon_epoll_ (struct MHD_Daemon *daemon, | |||
488 | while (NULL != (pos = prev)) | 488 | while (NULL != (pos = prev)) |
489 | { | 489 | { |
490 | prev = pos->prevX; | 490 | prev = pos->prevX; |
491 | MHD_connection_handle_idle (pos); | 491 | MHD_request_handle_idle_ (&pos->request); |
492 | } | 492 | } |
493 | /* Connections with the default timeout are sorted by prepending | 493 | /* Connections with the default timeout are sorted by prepending |
494 | them to the head of the list whenever we touch the connection; | 494 | them to the head of the list whenever we touch the connection; |
@@ -498,7 +498,7 @@ MHD_daemon_epoll_ (struct MHD_Daemon *daemon, | |||
498 | while (NULL != (pos = prev)) | 498 | while (NULL != (pos = prev)) |
499 | { | 499 | { |
500 | prev = pos->prevX; | 500 | prev = pos->prevX; |
501 | MHD_connection_handle_idle (pos); | 501 | MHD_request_handle_idle_ (&pos->request); |
502 | if (MHD_REQUEST_CLOSED != pos->request.state) | 502 | if (MHD_REQUEST_CLOSED != pos->request.state) |
503 | break; /* sorted by timeout, no need to visit the rest! */ | 503 | break; /* sorted by timeout, no need to visit the rest! */ |
504 | } | 504 | } |
diff --git a/src/lib/internal.h b/src/lib/internal.h index c90fdd2d..52be90d9 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h | |||
@@ -363,33 +363,6 @@ struct MHD_HTTP_Header | |||
363 | 363 | ||
364 | 364 | ||
365 | /** | 365 | /** |
366 | * What is this request waiting for? | ||
367 | */ | ||
368 | enum MHD_RequestEventLoopInfo | ||
369 | { | ||
370 | /** | ||
371 | * We are waiting to be able to read. | ||
372 | */ | ||
373 | MHD_EVENT_LOOP_INFO_READ = 0, | ||
374 | |||
375 | /** | ||
376 | * We are waiting to be able to write. | ||
377 | */ | ||
378 | MHD_EVENT_LOOP_INFO_WRITE = 1, | ||
379 | |||
380 | /** | ||
381 | * We are waiting for the application to provide data. | ||
382 | */ | ||
383 | MHD_EVENT_LOOP_INFO_BLOCK = 2, | ||
384 | |||
385 | /** | ||
386 | * We are finished and are awaiting cleanup. | ||
387 | */ | ||
388 | MHD_EVENT_LOOP_INFO_CLEANUP = 3 | ||
389 | }; | ||
390 | |||
391 | |||
392 | /** | ||
393 | * State kept for each HTTP request. | 366 | * State kept for each HTTP request. |
394 | */ | 367 | */ |
395 | struct MHD_Request | 368 | struct MHD_Request |