aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/connection.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-07-12 08:53:09 +0000
committerChristian Grothoff <christian@grothoff.org>2013-07-12 08:53:09 +0000
commit9e2d653d53c200fbf80e131fb5a53efa0f5fec7c (patch)
tree12595cc22cb277657470debc54057de7a51dba7a /src/microhttpd/connection.c
parent5946959f76fda2b28487d02d4329bc32f6ec7663 (diff)
downloadlibmicrohttpd-9e2d653d53c200fbf80e131fb5a53efa0f5fec7c.tar.gz
libmicrohttpd-9e2d653d53c200fbf80e131fb5a53efa0f5fec7c.zip
-update readiness state immediately after response is queued, to avoid going through another 'idle' event loop
Diffstat (limited to 'src/microhttpd/connection.c')
-rw-r--r--src/microhttpd/connection.c87
1 files changed, 44 insertions, 43 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 70661f9c..97fbd2d2 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -228,49 +228,6 @@ MHD_lookup_connection_value (struct MHD_Connection *connection,
228 228
229 229
230/** 230/**
231 * Queue a response to be transmitted to the client (as soon as
232 * possible but after MHD_AccessHandlerCallback returns).
233 *
234 * @param connection the connection identifying the client
235 * @param status_code HTTP status code (i.e. 200 for OK)
236 * @param response response to transmit
237 * @return MHD_NO on error (i.e. reply already sent),
238 * MHD_YES on success or if message has been queued
239 */
240int
241MHD_queue_response (struct MHD_Connection *connection,
242 unsigned int status_code, struct MHD_Response *response)
243{
244 if ( (NULL == connection) ||
245 (NULL == response) ||
246 (NULL != connection->response) ||
247 ( (MHD_CONNECTION_HEADERS_PROCESSED != connection->state) &&
248 (MHD_CONNECTION_FOOTERS_RECEIVED != connection->state) ) )
249 return MHD_NO;
250 MHD_increment_response_rc (response);
251 connection->response = response;
252 connection->responseCode = status_code;
253 if ( (NULL != connection->method) &&
254 (0 == strcasecmp (connection->method, MHD_HTTP_METHOD_HEAD)) )
255 {
256 /* if this is a "HEAD" request, pretend that we
257 have already sent the full message body */
258 connection->response_write_position = response->total_size;
259 }
260 if (MHD_CONNECTION_HEADERS_PROCESSED == connection->state)
261 {
262 /* response was queued "early",
263 refuse to read body / footers or further
264 requests! */
265 (void) SHUTDOWN (connection->socket_fd, SHUT_RD);
266 connection->read_closed = MHD_YES;
267 connection->state = MHD_CONNECTION_FOOTERS_RECEIVED;
268 }
269 return MHD_YES;
270}
271
272
273/**
274 * Do we (still) need to send a 100 continue 231 * Do we (still) need to send a 100 continue
275 * message for this connection? 232 * message for this connection?
276 * 233 *
@@ -2595,4 +2552,48 @@ MHD_set_connection_option (struct MHD_Connection *connection,
2595} 2552}
2596 2553
2597 2554
2555/**
2556 * Queue a response to be transmitted to the client (as soon as
2557 * possible but after MHD_AccessHandlerCallback returns).
2558 *
2559 * @param connection the connection identifying the client
2560 * @param status_code HTTP status code (i.e. 200 for OK)
2561 * @param response response to transmit
2562 * @return MHD_NO on error (i.e. reply already sent),
2563 * MHD_YES on success or if message has been queued
2564 */
2565int
2566MHD_queue_response (struct MHD_Connection *connection,
2567 unsigned int status_code, struct MHD_Response *response)
2568{
2569 if ( (NULL == connection) ||
2570 (NULL == response) ||
2571 (NULL != connection->response) ||
2572 ( (MHD_CONNECTION_HEADERS_PROCESSED != connection->state) &&
2573 (MHD_CONNECTION_FOOTERS_RECEIVED != connection->state) ) )
2574 return MHD_NO;
2575 MHD_increment_response_rc (response);
2576 connection->response = response;
2577 connection->responseCode = status_code;
2578 if ( (NULL != connection->method) &&
2579 (0 == strcasecmp (connection->method, MHD_HTTP_METHOD_HEAD)) )
2580 {
2581 /* if this is a "HEAD" request, pretend that we
2582 have already sent the full message body */
2583 connection->response_write_position = response->total_size;
2584 }
2585 if (MHD_CONNECTION_HEADERS_PROCESSED == connection->state)
2586 {
2587 /* response was queued "early",
2588 refuse to read body / footers or further
2589 requests! */
2590 (void) SHUTDOWN (connection->socket_fd, SHUT_RD);
2591 connection->read_closed = MHD_YES;
2592 connection->state = MHD_CONNECTION_FOOTERS_RECEIVED;
2593 }
2594 MHD_connection_update_event_loop_info (connection);
2595 return MHD_YES;
2596}
2597
2598
2598/* end of connection.c */ 2599/* end of connection.c */