aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/connection.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-10-24 08:41:04 +0000
committerChristian Grothoff <christian@grothoff.org>2013-10-24 08:41:04 +0000
commit8e6b1e789978929efd84aedf44943514dfe1a7e3 (patch)
treebc58d70919f93fdc43ab94d7da17c874aafe367c /src/microhttpd/connection.c
parenta79c58be3d55fb21d9d47bd6f7a3b5367ad70569 (diff)
downloadlibmicrohttpd-8e6b1e789978929efd84aedf44943514dfe1a7e3.tar.gz
libmicrohttpd-8e6b1e789978929efd84aedf44943514dfe1a7e3.zip
experimental code to support flow control for connections via MHD_suspend_connection and MHD_resume_connection
Diffstat (limited to 'src/microhttpd/connection.c')
-rw-r--r--src/microhttpd/connection.c171
1 files changed, 81 insertions, 90 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 6190fc29..63df4b94 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -148,7 +148,7 @@ MHD_get_connection_values (struct MHD_Connection *connection,
148 * them). This maybe required in certain situations (see Mantis 148 * them). This maybe required in certain situations (see Mantis
149 * #1399) where (broken) HTTP implementations fail to supply values 149 * #1399) where (broken) HTTP implementations fail to supply values
150 * needed by the post processor (or other parts of the application). 150 * needed by the post processor (or other parts of the application).
151 * 151 *
152 * This function MUST only be called from within the 152 * This function MUST only be called from within the
153 * #MHD_AccessHandlerCallback (otherwise, access maybe improperly 153 * #MHD_AccessHandlerCallback (otherwise, access maybe improperly
154 * synchronized). Furthermore, the client must guarantee that the key 154 * synchronized). Furthermore, the client must guarantee that the key
@@ -215,12 +215,12 @@ MHD_lookup_connection_value (struct MHD_Connection *connection,
215 if (NULL == connection) 215 if (NULL == connection)
216 return NULL; 216 return NULL;
217 for (pos = connection->headers_received; NULL != pos; pos = pos->next) 217 for (pos = connection->headers_received; NULL != pos; pos = pos->next)
218 if ((0 != (pos->kind & kind)) && 218 if ((0 != (pos->kind & kind)) &&
219 ( (key == pos->header) || 219 ( (key == pos->header) ||
220 ( (NULL != pos->header) && 220 ( (NULL != pos->header) &&
221 (NULL != key) && 221 (NULL != key) &&
222 (0 == strcasecmp (key, pos->header))) )) 222 (0 == strcasecmp (key, pos->header))) ))
223 return pos->value; 223 return pos->value;
224 return NULL; 224 return NULL;
225} 225}
226 226
@@ -265,13 +265,13 @@ MHD_connection_close (struct MHD_Connection *connection,
265 265
266 daemon = connection->daemon; 266 daemon = connection->daemon;
267 if (0 == (connection->daemon->options & MHD_USE_EPOLL_TURBO)) 267 if (0 == (connection->daemon->options & MHD_USE_EPOLL_TURBO))
268 SHUTDOWN (connection->socket_fd, 268 SHUTDOWN (connection->socket_fd,
269 (MHD_YES == connection->read_closed) ? SHUT_WR : SHUT_RDWR); 269 (MHD_YES == connection->read_closed) ? SHUT_WR : SHUT_RDWR);
270 connection->state = MHD_CONNECTION_CLOSED; 270 connection->state = MHD_CONNECTION_CLOSED;
271 connection->event_loop_info = MHD_EVENT_LOOP_INFO_CLEANUP; 271 connection->event_loop_info = MHD_EVENT_LOOP_INFO_CLEANUP;
272 if ( (NULL != daemon->notify_completed) && 272 if ( (NULL != daemon->notify_completed) &&
273 (MHD_YES == connection->client_aware) ) 273 (MHD_YES == connection->client_aware) )
274 daemon->notify_completed (daemon->notify_completed_cls, 274 daemon->notify_completed (daemon->notify_completed_cls,
275 connection, 275 connection,
276 &connection->client_context, 276 &connection->client_context,
277 termination_code); 277 termination_code);
@@ -342,25 +342,16 @@ try_ready_normal_body (struct MHD_Connection *connection)
342 (0 == (connection->daemon->options & MHD_USE_SSL)) ) 342 (0 == (connection->daemon->options & MHD_USE_SSL)) )
343 { 343 {
344 /* will use sendfile, no need to bother response crc */ 344 /* will use sendfile, no need to bother response crc */
345 return MHD_YES; 345 return MHD_YES;
346 } 346 }
347#endif 347#endif
348 348
349 ret = response->crc (response->crc_cls, 349 ret = response->crc (response->crc_cls,
350 connection->response_write_position, 350 connection->response_write_position,
351 response->data, 351 response->data,
352 MHD_MIN (response->data_buffer_size, 352 MHD_MIN (response->data_buffer_size,
353 response->total_size - 353 response->total_size -
354 connection->response_write_position)); 354 connection->response_write_position));
355 if ((0 == ret) &&
356 (0 != (connection->daemon->options & MHD_USE_SELECT_INTERNALLY)))
357 mhd_panic (mhd_panic_cls, __FILE__, __LINE__
358#if HAVE_MESSAGES
359 , "API violation"
360#else
361 , NULL
362#endif
363 );
364 if ( (MHD_CONTENT_READER_END_OF_STREAM == ret) || 355 if ( (MHD_CONTENT_READER_END_OF_STREAM == ret) ||
365 (MHD_CONTENT_READER_END_WITH_ERROR == ret) ) 356 (MHD_CONTENT_READER_END_WITH_ERROR == ret) )
366 { 357 {
@@ -368,7 +359,7 @@ try_ready_normal_body (struct MHD_Connection *connection)
368 response->total_size = connection->response_write_position; 359 response->total_size = connection->response_write_position;
369 if (NULL != response->crc) 360 if (NULL != response->crc)
370 pthread_mutex_unlock (&response->mutex); 361 pthread_mutex_unlock (&response->mutex);
371 if (MHD_CONTENT_READER_END_OF_STREAM == ret) 362 if (MHD_CONTENT_READER_END_OF_STREAM == ret)
372 MHD_connection_close (connection, MHD_REQUEST_TERMINATED_COMPLETED_OK); 363 MHD_connection_close (connection, MHD_REQUEST_TERMINATED_COMPLETED_OK);
373 else 364 else
374 CONNECTION_CLOSE_ERROR (connection, 365 CONNECTION_CLOSE_ERROR (connection,
@@ -470,14 +461,14 @@ try_ready_chunked_body (struct MHD_Connection *connection)
470 response->total_size = connection->response_write_position; 461 response->total_size = connection->response_write_position;
471 return MHD_YES; 462 return MHD_YES;
472 } 463 }
473 if (0 == ret) 464 if (0 == ret)
474 { 465 {
475 connection->state = MHD_CONNECTION_CHUNKED_BODY_UNREADY; 466 connection->state = MHD_CONNECTION_CHUNKED_BODY_UNREADY;
476 return MHD_NO; 467 return MHD_NO;
477 } 468 }
478 if (ret > 0xFFFFFF) 469 if (ret > 0xFFFFFF)
479 ret = 0xFFFFFF; 470 ret = 0xFFFFFF;
480 snprintf (cbuf, 471 snprintf (cbuf,
481 sizeof (cbuf), 472 sizeof (cbuf),
482 "%X\r\n", (unsigned int) ret); 473 "%X\r\n", (unsigned int) ret);
483 cblen = strlen (cbuf); 474 cblen = strlen (cbuf);
@@ -528,7 +519,7 @@ add_extra_headers (struct MHD_Connection *connection)
528 if the client asked for a close, no need to start chunk'ing */ 519 if the client asked for a close, no need to start chunk'ing */
529 if ((NULL == client_close) && 520 if ((NULL == client_close) &&
530 (NULL != connection->version) && 521 (NULL != connection->version) &&
531 (0 == strcasecmp (connection->version, MHD_HTTP_VERSION_1_1))) 522 (0 == strcasecmp (connection->version, MHD_HTTP_VERSION_1_1)))
532 { 523 {
533 connection->have_chunked_upload = MHD_YES; 524 connection->have_chunked_upload = MHD_YES;
534 have_encoding = MHD_get_response_header (connection->response, 525 have_encoding = MHD_get_response_header (connection->response,
@@ -562,17 +553,17 @@ add_extra_headers (struct MHD_Connection *connection)
562 MHD_HTTP_METHOD_CONNECT)) || 553 MHD_HTTP_METHOD_CONNECT)) ||
563 (0 != connection->response->total_size) ) ) 554 (0 != connection->response->total_size) ) )
564 { 555 {
565 /* 556 /*
566 Here we add a content-length if one is missing; however, 557 Here we add a content-length if one is missing; however,
567 for 'connect' methods, the responses MUST NOT include a 558 for 'connect' methods, the responses MUST NOT include a
568 content-length header *if* the response code is 2xx (in 559 content-length header *if* the response code is 2xx (in
569 which case we expect there to be no body). Still, 560 which case we expect there to be no body). Still,
570 as we don't know the response code here in some cases, we 561 as we don't know the response code here in some cases, we
571 simply only force adding a content-length header if this 562 simply only force adding a content-length header if this
572 is not a 'connect' or if the response is not empty 563 is not a 'connect' or if the response is not empty
573 (which is kind of more sane, because if some crazy 564 (which is kind of more sane, because if some crazy
574 application did return content with a 2xx status code, 565 application did return content with a 2xx status code,
575 then having a content-length might again be a good idea). 566 then having a content-length might again be a good idea).
576 567
577 Note that the change from 'SHOULD NOT' to 'MUST NOT' is 568 Note that the change from 'SHOULD NOT' to 'MUST NOT' is
578 a recent development of the HTTP 1.1 specification. 569 a recent development of the HTTP 1.1 specification.
@@ -616,8 +607,8 @@ get_date_string (char *date)
616 (unsigned int) now.tm_mday, 607 (unsigned int) now.tm_mday,
617 mons[now.tm_mon % 12], 608 mons[now.tm_mon % 12],
618 (unsigned int) (1900 + now.tm_year), 609 (unsigned int) (1900 + now.tm_year),
619 (unsigned int) now.tm_hour, 610 (unsigned int) now.tm_hour,
620 (unsigned int) now.tm_min, 611 (unsigned int) now.tm_min,
621 (unsigned int) now.tm_sec); 612 (unsigned int) now.tm_sec);
622} 613}
623 614
@@ -626,7 +617,7 @@ get_date_string (char *date)
626 * Try growing the read buffer. We initially claim half the 617 * Try growing the read buffer. We initially claim half the
627 * available buffer space for the read buffer (the other half 618 * available buffer space for the read buffer (the other half
628 * being left for management data structures; the write 619 * being left for management data structures; the write
629 * buffer can in the end take virtually everything as the 620 * buffer can in the end take virtually everything as the
630 * read buffer can be reduced to the minimum necessary at that 621 * read buffer can be reduced to the minimum necessary at that
631 * point. 622 * point.
632 * 623 *
@@ -696,18 +687,18 @@ build_header_response (struct MHD_Connection *connection)
696 SPRINTF (code, 687 SPRINTF (code,
697 "%s %u %s\r\n", 688 "%s %u %s\r\n",
698 (0 != (connection->responseCode & MHD_ICY_FLAG)) 689 (0 != (connection->responseCode & MHD_ICY_FLAG))
699 ? "ICY" 690 ? "ICY"
700 : ( (0 == strcasecmp (MHD_HTTP_VERSION_1_0, 691 : ( (0 == strcasecmp (MHD_HTTP_VERSION_1_0,
701 connection->version)) 692 connection->version))
702 ? MHD_HTTP_VERSION_1_0 693 ? MHD_HTTP_VERSION_1_0
703 : MHD_HTTP_VERSION_1_1), 694 : MHD_HTTP_VERSION_1_1),
704 rc, 695 rc,
705 reason_phrase); 696 reason_phrase);
706 off = strlen (code); 697 off = strlen (code);
707 /* estimate size */ 698 /* estimate size */
708 size = off + 2; /* extra \r\n at the end */ 699 size = off + 2; /* extra \r\n at the end */
709 kind = MHD_HEADER_KIND; 700 kind = MHD_HEADER_KIND;
710 if ( (0 == (connection->daemon->options & MHD_SUPPRESS_DATE_NO_CLOCK)) && 701 if ( (0 == (connection->daemon->options & MHD_SUPPRESS_DATE_NO_CLOCK)) &&
711 (NULL == MHD_get_response_header (connection->response, 702 (NULL == MHD_get_response_header (connection->response,
712 MHD_HTTP_HEADER_DATE)) ) 703 MHD_HTTP_HEADER_DATE)) )
713 get_date_string (date); 704 get_date_string (date);
@@ -757,9 +748,9 @@ build_header_response (struct MHD_Connection *connection)
757 } 748 }
758 for (pos = connection->response->first_header; NULL != pos; pos = pos->next) 749 for (pos = connection->response->first_header; NULL != pos; pos = pos->next)
759 if (pos->kind == kind) 750 if (pos->kind == kind)
760 off += SPRINTF (&data[off], 751 off += SPRINTF (&data[off],
761 "%s: %s\r\n", 752 "%s: %s\r\n",
762 pos->header, 753 pos->header,
763 pos->value); 754 pos->value);
764 if (connection->state == MHD_CONNECTION_FOOTERS_RECEIVED) 755 if (connection->state == MHD_CONNECTION_FOOTERS_RECEIVED)
765 { 756 {
@@ -790,7 +781,7 @@ build_header_response (struct MHD_Connection *connection)
790 */ 781 */
791static void 782static void
792transmit_error_response (struct MHD_Connection *connection, 783transmit_error_response (struct MHD_Connection *connection,
793 unsigned int status_code, 784 unsigned int status_code,
794 const char *message) 785 const char *message)
795{ 786{
796 struct MHD_Response *response; 787 struct MHD_Response *response;
@@ -810,7 +801,7 @@ transmit_error_response (struct MHD_Connection *connection,
810#endif 801#endif
811 EXTRA_CHECK (NULL == connection->response); 802 EXTRA_CHECK (NULL == connection->response);
812 response = MHD_create_response_from_buffer (strlen (message), 803 response = MHD_create_response_from_buffer (strlen (message),
813 (void *) message, 804 (void *) message,
814 MHD_RESPMEM_PERSISTENT); 805 MHD_RESPMEM_PERSISTENT);
815 MHD_queue_response (connection, status_code, response); 806 MHD_queue_response (connection, status_code, response);
816 EXTRA_CHECK (NULL != connection->response); 807 EXTRA_CHECK (NULL != connection->response);
@@ -834,7 +825,7 @@ transmit_error_response (struct MHD_Connection *connection,
834 * perform other updates to the connection if needed to prepare for 825 * perform other updates to the connection if needed to prepare for
835 * the next round of the event loop. 826 * the next round of the event loop.
836 * 827 *
837 * @param connection connetion to get poll set for 828 * @param connection connetion to get poll set for
838 */ 829 */
839static void 830static void
840MHD_connection_update_event_loop_info (struct MHD_Connection *connection) 831MHD_connection_update_event_loop_info (struct MHD_Connection *connection)
@@ -847,7 +838,7 @@ MHD_connection_update_event_loop_info (struct MHD_Connection *connection)
847#endif 838#endif
848 switch (connection->state) 839 switch (connection->state)
849 { 840 {
850#if HTTPS_SUPPORT 841#if HTTPS_SUPPORT
851 case MHD_TLS_CONNECTION_INIT: 842 case MHD_TLS_CONNECTION_INIT:
852 if (0 == gnutls_record_get_direction (connection->tls_session)) 843 if (0 == gnutls_record_get_direction (connection->tls_session))
853 connection->event_loop_info = MHD_EVENT_LOOP_INFO_READ; 844 connection->event_loop_info = MHD_EVENT_LOOP_INFO_READ;
@@ -921,7 +912,7 @@ MHD_connection_update_event_loop_info (struct MHD_Connection *connection)
921 read buffer if needed, no size-check required */ 912 read buffer if needed, no size-check required */
922 if (MHD_YES == connection->read_closed) 913 if (MHD_YES == connection->read_closed)
923 { 914 {
924 CONNECTION_CLOSE_ERROR (connection, 915 CONNECTION_CLOSE_ERROR (connection,
925 NULL); 916 NULL);
926 continue; 917 continue;
927 } 918 }
@@ -1000,7 +991,7 @@ get_next_header_line (struct MHD_Connection *connection)
1000 { 991 {
1001 /* not found, consider growing... */ 992 /* not found, consider growing... */
1002 if ( (connection->read_buffer_offset == connection->read_buffer_size) && 993 if ( (connection->read_buffer_offset == connection->read_buffer_size) &&
1003 (MHD_NO == 994 (MHD_NO ==
1004 try_grow_read_buffer (connection)) ) 995 try_grow_read_buffer (connection)) )
1005 { 996 {
1006 transmit_error_response (connection, 997 transmit_error_response (connection,
@@ -1008,7 +999,7 @@ get_next_header_line (struct MHD_Connection *connection)
1008 ? MHD_HTTP_REQUEST_ENTITY_TOO_LARGE 999 ? MHD_HTTP_REQUEST_ENTITY_TOO_LARGE
1009 : MHD_HTTP_REQUEST_URI_TOO_LONG, 1000 : MHD_HTTP_REQUEST_URI_TOO_LONG,
1010 REQUEST_TOO_BIG); 1001 REQUEST_TOO_BIG);
1011 } 1002 }
1012 return NULL; 1003 return NULL;
1013 } 1004 }
1014 /* found, check if we have proper LFCR */ 1005 /* found, check if we have proper LFCR */
@@ -1064,7 +1055,7 @@ connection_add_header (struct MHD_Connection *connection,
1064 */ 1055 */
1065static int 1056static int
1066parse_arguments (enum MHD_ValueKind kind, 1057parse_arguments (enum MHD_ValueKind kind,
1067 struct MHD_Connection *connection, 1058 struct MHD_Connection *connection,
1068 char *args) 1059 char *args)
1069{ 1060{
1070 char *equals; 1061 char *equals;
@@ -1086,7 +1077,7 @@ parse_arguments (enum MHD_ValueKind kind,
1086 return connection_add_header (connection, 1077 return connection_add_header (connection,
1087 args, 1078 args,
1088 NULL, 1079 NULL,
1089 kind); 1080 kind);
1090 } 1081 }
1091 /* got 'foo=bar' */ 1082 /* got 'foo=bar' */
1092 equals[0] = '\0'; 1083 equals[0] = '\0';
@@ -1261,7 +1252,7 @@ parse_initial_message_line (struct MHD_Connection *connection, char *line)
1261 } 1252 }
1262 if (NULL != connection->daemon->uri_log_callback) 1253 if (NULL != connection->daemon->uri_log_callback)
1263 connection->client_context 1254 connection->client_context
1264 = connection->daemon->uri_log_callback (connection->daemon->uri_log_callback_cls, 1255 = connection->daemon->uri_log_callback (connection->daemon->uri_log_callback_cls,
1265 uri, 1256 uri,
1266 connection); 1257 connection);
1267 args = strchr (uri, '?'); 1258 args = strchr (uri, '?');
@@ -1296,7 +1287,7 @@ call_connection_handler (struct MHD_Connection *connection)
1296 size_t processed; 1287 size_t processed;
1297 1288
1298 if (NULL != connection->response) 1289 if (NULL != connection->response)
1299 return; /* already queued a response */ 1290 return; /* already queued a response */
1300 processed = 0; 1291 processed = 0;
1301 connection->client_aware = MHD_YES; 1292 connection->client_aware = MHD_YES;
1302 if (MHD_NO == 1293 if (MHD_NO ==
@@ -1309,7 +1300,7 @@ call_connection_handler (struct MHD_Connection *connection)
1309 &connection->client_context)) 1300 &connection->client_context))
1310 { 1301 {
1311 /* serious internal error, close connection */ 1302 /* serious internal error, close connection */
1312 CONNECTION_CLOSE_ERROR (connection, 1303 CONNECTION_CLOSE_ERROR (connection,
1313 "Internal application error, closing connection.\n"); 1304 "Internal application error, closing connection.\n");
1314 return; 1305 return;
1315 } 1306 }
@@ -1438,7 +1429,7 @@ process_request_body (struct MHD_Connection *connection)
1438 else 1429 else
1439 { 1430 {
1440 /* no chunked encoding, give all to the client */ 1431 /* no chunked encoding, give all to the client */
1441 if ( (0 != connection->remaining_upload_size) && 1432 if ( (0 != connection->remaining_upload_size) &&
1442 (MHD_SIZE_UNKNOWN != connection->remaining_upload_size) && 1433 (MHD_SIZE_UNKNOWN != connection->remaining_upload_size) &&
1443 (connection->remaining_upload_size < available) ) 1434 (connection->remaining_upload_size < available) )
1444 { 1435 {
@@ -1527,7 +1518,7 @@ do_read (struct MHD_Connection *connection)
1527 "Failed to receive data: %s\n", 1518 "Failed to receive data: %s\n",
1528 gnutls_strerror (bytes_read)); 1519 gnutls_strerror (bytes_read));
1529 else 1520 else
1530#endif 1521#endif
1531 MHD_DLOG (connection->daemon, 1522 MHD_DLOG (connection->daemon,
1532 "Failed to receive data: %s\n", STRERROR (errno)); 1523 "Failed to receive data: %s\n", STRERROR (errno));
1533#endif 1524#endif
@@ -1577,7 +1568,7 @@ do_write (struct MHD_Connection *connection)
1577 "Failed to send data: %s\n", 1568 "Failed to send data: %s\n",
1578 gnutls_strerror (ret)); 1569 gnutls_strerror (ret));
1579 else 1570 else
1580#endif 1571#endif
1581 MHD_DLOG (connection->daemon, 1572 MHD_DLOG (connection->daemon,
1582 "Failed to send data: %s\n", STRERROR (errno)); 1573 "Failed to send data: %s\n", STRERROR (errno));
1583#endif 1574#endif
@@ -1613,7 +1604,7 @@ check_write_done (struct MHD_Connection *connection,
1613 connection->write_buffer_append_offset = 0; 1604 connection->write_buffer_append_offset = 0;
1614 connection->write_buffer_send_offset = 0; 1605 connection->write_buffer_send_offset = 0;
1615 connection->state = next_state; 1606 connection->state = next_state;
1616 MHD_pool_reallocate (connection->pool, 1607 MHD_pool_reallocate (connection->pool,
1617 connection->write_buffer, 1608 connection->write_buffer,
1618 connection->write_buffer_size, 0); 1609 connection->write_buffer_size, 0);
1619 connection->write_buffer = NULL; 1610 connection->write_buffer = NULL;
@@ -1641,7 +1632,7 @@ process_header_line (struct MHD_Connection *connection, char *line)
1641 if (NULL == colon) 1632 if (NULL == colon)
1642 { 1633 {
1643 /* error in header line, die hard */ 1634 /* error in header line, die hard */
1644 CONNECTION_CLOSE_ERROR (connection, 1635 CONNECTION_CLOSE_ERROR (connection,
1645 "Received malformed line (no colon), closing connection.\n"); 1636 "Received malformed line (no colon), closing connection.\n");
1646 return MHD_NO; 1637 return MHD_NO;
1647 } 1638 }
@@ -1689,7 +1680,7 @@ process_broken_line (struct MHD_Connection *connection,
1689 /* skip whitespace at start of 2nd line */ 1680 /* skip whitespace at start of 2nd line */
1690 tmp = line; 1681 tmp = line;
1691 while ((tmp[0] == ' ') || (tmp[0] == '\t')) 1682 while ((tmp[0] == ' ') || (tmp[0] == '\t'))
1692 tmp++; 1683 tmp++;
1693 tmp_len = strlen (tmp); 1684 tmp_len = strlen (tmp);
1694 /* FIXME: we might be able to do this better (faster!), as most 1685 /* FIXME: we might be able to do this better (faster!), as most
1695 likely 'last' and 'line' should already be adjacent in 1686 likely 'last' and 'line' should already be adjacent in
@@ -1833,7 +1824,7 @@ update_last_activity (struct MHD_Connection *connection)
1833 /* move connection to head of timeout list (by remove + add operation) */ 1824 /* move connection to head of timeout list (by remove + add operation) */
1834 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1825 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1835 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) ) 1826 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) )
1836 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 1827 MHD_PANIC ("Failed to acquire cleanup mutex\n");
1837 XDLL_remove (daemon->normal_timeout_head, 1828 XDLL_remove (daemon->normal_timeout_head,
1838 daemon->normal_timeout_tail, 1829 daemon->normal_timeout_tail,
1839 connection); 1830 connection);
@@ -1842,13 +1833,13 @@ update_last_activity (struct MHD_Connection *connection)
1842 connection); 1833 connection);
1843 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1834 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
1844 (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) ) 1835 (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) )
1845 MHD_PANIC ("Failed to release cleanup mutex\n"); 1836 MHD_PANIC ("Failed to release cleanup mutex\n");
1846} 1837}
1847 1838
1848 1839
1849/** 1840/**
1850 * This function handles a particular connection when it has been 1841 * This function handles a particular connection when it has been
1851 * determined that there is data to be read off a socket. 1842 * determined that there is data to be read off a socket.
1852 * 1843 *
1853 * @param connection connection to handle 1844 * @param connection connection to handle
1854 * @return always #MHD_YES (we should continue to process the 1845 * @return always #MHD_YES (we should continue to process the
@@ -1982,10 +1973,10 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
1982 break; 1973 break;
1983 case MHD_CONNECTION_NORMAL_BODY_READY: 1974 case MHD_CONNECTION_NORMAL_BODY_READY:
1984 response = connection->response; 1975 response = connection->response;
1985 if (response->crc != NULL) 1976 if (NULL != response->crc)
1986 pthread_mutex_lock (&response->mutex); 1977 pthread_mutex_lock (&response->mutex);
1987 if (MHD_YES != try_ready_normal_body (connection)) 1978 if (MHD_YES != try_ready_normal_body (connection))
1988 break; 1979 break;
1989 ret = connection->send_cls (connection, 1980 ret = connection->send_cls (connection,
1990 &response->data 1981 &response->data
1991 [connection->response_write_position 1982 [connection->response_write_position
@@ -2001,7 +1992,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
2001 &response->data[connection->response_write_position - 1992 &response->data[connection->response_write_position -
2002 response->data_start]); 1993 response->data_start]);
2003#endif 1994#endif
2004 if (response->crc != NULL) 1995 if (NULL != response->crc)
2005 pthread_mutex_unlock (&response->mutex); 1996 pthread_mutex_unlock (&response->mutex);
2006 if (ret < 0) 1997 if (ret < 0)
2007 { 1998 {
@@ -2078,8 +2069,8 @@ cleanup_connection (struct MHD_Connection *connection)
2078 connection->response = NULL; 2069 connection->response = NULL;
2079 } 2070 }
2080 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 2071 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
2081 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) ) 2072 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) )
2082 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 2073 MHD_PANIC ("Failed to acquire cleanup mutex\n");
2083 if (connection->connection_timeout == daemon->connection_timeout) 2074 if (connection->connection_timeout == daemon->connection_timeout)
2084 XDLL_remove (daemon->normal_timeout_head, 2075 XDLL_remove (daemon->normal_timeout_head,
2085 daemon->normal_timeout_tail, 2076 daemon->normal_timeout_tail,
@@ -2095,15 +2086,15 @@ cleanup_connection (struct MHD_Connection *connection)
2095 daemon->cleanup_tail, 2086 daemon->cleanup_tail,
2096 connection); 2087 connection);
2097 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 2088 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
2098 (0 != pthread_mutex_unlock(&daemon->cleanup_connection_mutex)) ) 2089 (0 != pthread_mutex_unlock(&daemon->cleanup_connection_mutex)) )
2099 MHD_PANIC ("Failed to release cleanup mutex\n"); 2090 MHD_PANIC ("Failed to release cleanup mutex\n");
2100 connection->in_idle = MHD_NO; 2091 connection->in_idle = MHD_NO;
2101} 2092}
2102 2093
2103 2094
2104/** 2095/**
2105 * This function was created to handle per-connection processing that 2096 * This function was created to handle per-connection processing that
2106 * has to happen even if the socket cannot be read or written to. 2097 * has to happen even if the socket cannot be read or written to.
2107 * 2098 *
2108 * @param connection connection to handle 2099 * @param connection connection to handle
2109 * @return #MHD_YES if we should continue to process the 2100 * @return #MHD_YES if we should continue to process the
@@ -2135,7 +2126,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2135 continue; 2126 continue;
2136 if (MHD_YES == connection->read_closed) 2127 if (MHD_YES == connection->read_closed)
2137 { 2128 {
2138 CONNECTION_CLOSE_ERROR (connection, 2129 CONNECTION_CLOSE_ERROR (connection,
2139 NULL); 2130 NULL);
2140 continue; 2131 continue;
2141 } 2132 }
@@ -2154,7 +2145,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2154 continue; 2145 continue;
2155 if (MHD_YES == connection->read_closed) 2146 if (MHD_YES == connection->read_closed)
2156 { 2147 {
2157 CONNECTION_CLOSE_ERROR (connection, 2148 CONNECTION_CLOSE_ERROR (connection,
2158 NULL); 2149 NULL);
2159 continue; 2150 continue;
2160 } 2151 }
@@ -2182,7 +2173,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2182 continue; 2173 continue;
2183 if (MHD_YES == connection->read_closed) 2174 if (MHD_YES == connection->read_closed)
2184 { 2175 {
2185 CONNECTION_CLOSE_ERROR (connection, 2176 CONNECTION_CLOSE_ERROR (connection,
2186 NULL); 2177 NULL);
2187 continue; 2178 continue;
2188 } 2179 }
@@ -2262,7 +2253,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2262 continue; 2253 continue;
2263 if (MHD_YES == connection->read_closed) 2254 if (MHD_YES == connection->read_closed)
2264 { 2255 {
2265 CONNECTION_CLOSE_ERROR (connection, 2256 CONNECTION_CLOSE_ERROR (connection,
2266 NULL); 2257 NULL);
2267 continue; 2258 continue;
2268 } 2259 }
@@ -2290,7 +2281,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2290 continue; 2281 continue;
2291 if (MHD_YES == connection->read_closed) 2282 if (MHD_YES == connection->read_closed)
2292 { 2283 {
2293 CONNECTION_CLOSE_ERROR (connection, 2284 CONNECTION_CLOSE_ERROR (connection,
2294 NULL); 2285 NULL);
2295 continue; 2286 continue;
2296 } 2287 }
@@ -2314,7 +2305,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2314 if (MHD_NO == build_header_response (connection)) 2305 if (MHD_NO == build_header_response (connection))
2315 { 2306 {
2316 /* oops - close! */ 2307 /* oops - close! */
2317 CONNECTION_CLOSE_ERROR (connection, 2308 CONNECTION_CLOSE_ERROR (connection,
2318 "Closing connection (failed to create response header)\n"); 2309 "Closing connection (failed to create response header)\n");
2319 continue; 2310 continue;
2320 } 2311 }
@@ -2342,11 +2333,11 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2342 /* nothing to do here */ 2333 /* nothing to do here */
2343 break; 2334 break;
2344 case MHD_CONNECTION_NORMAL_BODY_UNREADY: 2335 case MHD_CONNECTION_NORMAL_BODY_UNREADY:
2345 if (connection->response->crc != NULL) 2336 if (NULL != connection->response->crc)
2346 pthread_mutex_lock (&connection->response->mutex); 2337 pthread_mutex_lock (&connection->response->mutex);
2347 if (0 == connection->response->total_size) 2338 if (0 == connection->response->total_size)
2348 { 2339 {
2349 if (connection->response->crc != NULL) 2340 if (NULL != connection->response->crc)
2350 pthread_mutex_unlock (&connection->response->mutex); 2341 pthread_mutex_unlock (&connection->response->mutex);
2351 connection->state = MHD_CONNECTION_BODY_SENT; 2342 connection->state = MHD_CONNECTION_BODY_SENT;
2352 continue; 2343 continue;
@@ -2364,23 +2355,23 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2364 /* nothing to do here */ 2355 /* nothing to do here */
2365 break; 2356 break;
2366 case MHD_CONNECTION_CHUNKED_BODY_UNREADY: 2357 case MHD_CONNECTION_CHUNKED_BODY_UNREADY:
2367 if (connection->response->crc != NULL) 2358 if (NULL != connection->response->crc)
2368 pthread_mutex_lock (&connection->response->mutex); 2359 pthread_mutex_lock (&connection->response->mutex);
2369 if (0 == connection->response->total_size) 2360 if (0 == connection->response->total_size)
2370 { 2361 {
2371 if (connection->response->crc != NULL) 2362 if (NULL != connection->response->crc)
2372 pthread_mutex_unlock (&connection->response->mutex); 2363 pthread_mutex_unlock (&connection->response->mutex);
2373 connection->state = MHD_CONNECTION_BODY_SENT; 2364 connection->state = MHD_CONNECTION_BODY_SENT;
2374 continue; 2365 continue;
2375 } 2366 }
2376 if (MHD_YES == try_ready_chunked_body (connection)) 2367 if (MHD_YES == try_ready_chunked_body (connection))
2377 { 2368 {
2378 if (connection->response->crc != NULL) 2369 if (NULL != connection->response->crc)
2379 pthread_mutex_unlock (&connection->response->mutex); 2370 pthread_mutex_unlock (&connection->response->mutex);
2380 connection->state = MHD_CONNECTION_CHUNKED_BODY_READY; 2371 connection->state = MHD_CONNECTION_CHUNKED_BODY_READY;
2381 continue; 2372 continue;
2382 } 2373 }
2383 if (connection->response->crc != NULL) 2374 if (NULL != connection->response->crc)
2384 pthread_mutex_unlock (&connection->response->mutex); 2375 pthread_mutex_unlock (&connection->response->mutex);
2385 break; 2376 break;
2386 case MHD_CONNECTION_BODY_SENT: 2377 case MHD_CONNECTION_BODY_SENT:
@@ -2404,7 +2395,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2404 } 2395 }
2405#endif 2396#endif
2406 end = 2397 end =
2407 MHD_get_response_header (connection->response, 2398 MHD_get_response_header (connection->response,
2408 MHD_HTTP_HEADER_CONNECTION); 2399 MHD_HTTP_HEADER_CONNECTION);
2409 rend = ( (MHD_YES == connection->read_closed) || 2400 rend = ( (MHD_YES == connection->read_closed) ||
2410 ( (end != NULL) && (0 == strcasecmp (end, "close")) ) ); 2401 ( (end != NULL) && (0 == strcasecmp (end, "close")) ) );
@@ -2414,7 +2405,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2414 daemon->notify_completed (daemon->notify_completed_cls, 2405 daemon->notify_completed (daemon->notify_completed_cls,
2415 connection, 2406 connection,
2416 &connection->client_context, 2407 &connection->client_context,
2417 MHD_REQUEST_TERMINATED_COMPLETED_OK); 2408 MHD_REQUEST_TERMINATED_COMPLETED_OK);
2418 connection->client_aware = MHD_NO; 2409 connection->client_aware = MHD_NO;
2419 end = 2410 end =
2420 MHD_lookup_connection_value (connection, MHD_HEADER_KIND, 2411 MHD_lookup_connection_value (connection, MHD_HEADER_KIND,
@@ -2478,7 +2469,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2478 return MHD_YES; 2469 return MHD_YES;
2479 } 2470 }
2480 MHD_connection_update_event_loop_info (connection); 2471 MHD_connection_update_event_loop_info (connection);
2481#if EPOLL_SUPPORT 2472#if EPOLL_SUPPORT
2482 switch (connection->event_loop_info) 2473 switch (connection->event_loop_info)
2483 { 2474 {
2484 case MHD_EVENT_LOOP_INFO_READ: 2475 case MHD_EVENT_LOOP_INFO_READ:
@@ -2492,7 +2483,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2492 } 2483 }
2493 break; 2484 break;
2494 case MHD_EVENT_LOOP_INFO_WRITE: 2485 case MHD_EVENT_LOOP_INFO_WRITE:
2495 if ( (connection->read_buffer_size > connection->read_buffer_offset) && 2486 if ( (connection->read_buffer_size > connection->read_buffer_offset) &&
2496 (0 != (connection->epoll_state & MHD_EPOLL_STATE_READ_READY)) && 2487 (0 != (connection->epoll_state & MHD_EPOLL_STATE_READ_READY)) &&
2497 (0 == (connection->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL)) ) 2488 (0 == (connection->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL)) )
2498 { 2489 {
@@ -2517,7 +2508,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2517 { 2508 {
2518 EDLL_insert (daemon->eready_head, 2509 EDLL_insert (daemon->eready_head,
2519 daemon->eready_tail, 2510 daemon->eready_tail,
2520 connection); 2511 connection);
2521 connection->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL; 2512 connection->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL;
2522 } 2513 }
2523 break; 2514 break;
@@ -2540,13 +2531,13 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2540 * @param connection connection to process 2531 * @param connection connection to process
2541 * @return #MHD_YES if we should continue to process the 2532 * @return #MHD_YES if we should continue to process the
2542 * connection (not dead yet), #MHD_NO if it died 2533 * connection (not dead yet), #MHD_NO if it died
2543 */ 2534 */
2544int 2535int
2545MHD_connection_epoll_update_ (struct MHD_Connection *connection) 2536MHD_connection_epoll_update_ (struct MHD_Connection *connection)
2546{ 2537{
2547 struct MHD_Daemon *daemon = connection->daemon; 2538 struct MHD_Daemon *daemon = connection->daemon;
2548 2539
2549 if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) && 2540 if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) &&
2550 (0 == (connection->epoll_state & MHD_EPOLL_STATE_IN_EPOLL_SET)) && 2541 (0 == (connection->epoll_state & MHD_EPOLL_STATE_IN_EPOLL_SET)) &&
2551 ( (0 == (connection->epoll_state & MHD_EPOLL_STATE_WRITE_READY)) || 2542 ( (0 == (connection->epoll_state & MHD_EPOLL_STATE_WRITE_READY)) ||
2552 ( (0 == (connection->epoll_state & MHD_EPOLL_STATE_READ_READY)) && 2543 ( (0 == (connection->epoll_state & MHD_EPOLL_STATE_READ_READY)) &&
@@ -2558,7 +2549,7 @@ MHD_connection_epoll_update_ (struct MHD_Connection *connection)
2558 struct epoll_event event; 2549 struct epoll_event event;
2559 2550
2560 event.events = EPOLLIN | EPOLLOUT | EPOLLET; 2551 event.events = EPOLLIN | EPOLLOUT | EPOLLET;
2561 event.data.ptr = connection; 2552 event.data.ptr = connection;
2562 if (0 != epoll_ctl (daemon->epoll_fd, 2553 if (0 != epoll_ctl (daemon->epoll_fd,
2563 EPOLL_CTL_ADD, 2554 EPOLL_CTL_ADD,
2564 connection->socket_fd, 2555 connection->socket_fd,
@@ -2566,8 +2557,8 @@ MHD_connection_epoll_update_ (struct MHD_Connection *connection)
2566 { 2557 {
2567#if HAVE_MESSAGES 2558#if HAVE_MESSAGES
2568 if (0 != (daemon->options & MHD_USE_DEBUG)) 2559 if (0 != (daemon->options & MHD_USE_DEBUG))
2569 MHD_DLOG (daemon, 2560 MHD_DLOG (daemon,
2570 "Call to epoll_ctl failed: %s\n", 2561 "Call to epoll_ctl failed: %s\n",
2571 STRERROR (errno)); 2562 STRERROR (errno));
2572#endif 2563#endif
2573 connection->state = MHD_CONNECTION_CLOSED; 2564 connection->state = MHD_CONNECTION_CLOSED;
@@ -2649,7 +2640,7 @@ MHD_get_connection_info (struct MHD_Connection *connection,
2649 * @return #MHD_YES on success, #MHD_NO if setting the option failed 2640 * @return #MHD_YES on success, #MHD_NO if setting the option failed
2650 * @ingroup specialized 2641 * @ingroup specialized
2651 */ 2642 */
2652int 2643int
2653MHD_set_connection_option (struct MHD_Connection *connection, 2644MHD_set_connection_option (struct MHD_Connection *connection,
2654 enum MHD_CONNECTION_OPTION option, 2645 enum MHD_CONNECTION_OPTION option,
2655 ...) 2646 ...)
@@ -2657,13 +2648,13 @@ MHD_set_connection_option (struct MHD_Connection *connection,
2657 va_list ap; 2648 va_list ap;
2658 struct MHD_Daemon *daemon; 2649 struct MHD_Daemon *daemon;
2659 2650
2660 daemon = connection->daemon; 2651 daemon = connection->daemon;
2661 switch (option) 2652 switch (option)
2662 { 2653 {
2663 case MHD_CONNECTION_OPTION_TIMEOUT: 2654 case MHD_CONNECTION_OPTION_TIMEOUT:
2664 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 2655 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
2665 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) ) 2656 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) )
2666 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 2657 MHD_PANIC ("Failed to acquire cleanup mutex\n");
2667 if (connection->connection_timeout == daemon->connection_timeout) 2658 if (connection->connection_timeout == daemon->connection_timeout)
2668 XDLL_remove (daemon->normal_timeout_head, 2659 XDLL_remove (daemon->normal_timeout_head,
2669 daemon->normal_timeout_tail, 2660 daemon->normal_timeout_tail,
@@ -2685,7 +2676,7 @@ MHD_set_connection_option (struct MHD_Connection *connection,
2685 connection); 2676 connection);
2686 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 2677 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
2687 (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) ) 2678 (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) )
2688 MHD_PANIC ("Failed to release cleanup mutex\n"); 2679 MHD_PANIC ("Failed to release cleanup mutex\n");
2689 return MHD_YES; 2680 return MHD_YES;
2690 default: 2681 default:
2691 return MHD_NO; 2682 return MHD_NO;