diff options
Diffstat (limited to 'src/lib/connection_update_event_loop_info.c')
-rw-r--r-- | src/lib/connection_update_event_loop_info.c | 195 |
1 files changed, 0 insertions, 195 deletions
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 | |||