diff options
Diffstat (limited to 'src/daemon/connection.c')
-rw-r--r-- | src/daemon/connection.c | 225 |
1 files changed, 115 insertions, 110 deletions
diff --git a/src/daemon/connection.c b/src/daemon/connection.c index 33571ea9..54cbb17d 100644 --- a/src/daemon/connection.c +++ b/src/daemon/connection.c | |||
@@ -275,6 +275,7 @@ need_100_continue (struct MHD_Connection *connection) | |||
275 | strlen (HTTP_100_CONTINUE))); | 275 | strlen (HTTP_100_CONTINUE))); |
276 | } | 276 | } |
277 | 277 | ||
278 | |||
278 | /** | 279 | /** |
279 | * Close the given connection and give the | 280 | * Close the given connection and give the |
280 | * specified termination code to the user. | 281 | * specified termination code to the user. |
@@ -283,31 +284,52 @@ void | |||
283 | MHD_connection_close (struct MHD_Connection *connection, | 284 | MHD_connection_close (struct MHD_Connection *connection, |
284 | enum MHD_RequestTerminationCode termination_code) | 285 | enum MHD_RequestTerminationCode termination_code) |
285 | { | 286 | { |
287 | struct MHD_Daemon *daemon; | ||
288 | |||
289 | daemon = connection->daemon; | ||
286 | SHUTDOWN (connection->socket_fd, SHUT_RDWR); | 290 | SHUTDOWN (connection->socket_fd, SHUT_RDWR); |
287 | CLOSE (connection->socket_fd); | ||
288 | connection->socket_fd = -1; | ||
289 | connection->state = MHD_CONNECTION_CLOSED; | 291 | connection->state = MHD_CONNECTION_CLOSED; |
290 | if ( (NULL != connection->daemon->notify_completed) && | 292 | if ( (NULL != daemon->notify_completed) && |
291 | (MHD_YES == connection->client_aware) ) | 293 | (MHD_YES == connection->client_aware) ) |
292 | connection->daemon->notify_completed (connection->daemon-> | 294 | daemon->notify_completed (daemon->notify_completed_cls, |
293 | notify_completed_cls, connection, | 295 | connection, |
294 | &connection->client_context, | 296 | &connection->client_context, |
295 | termination_code); | 297 | termination_code); |
296 | connection->client_aware = MHD_NO; | 298 | connection->client_aware = MHD_NO; |
297 | } | 299 | } |
298 | 300 | ||
301 | |||
299 | /** | 302 | /** |
300 | * A serious error occured, close the | 303 | * A serious error occured, close the |
301 | * connection (and notify the application). | 304 | * connection (and notify the application). |
305 | * | ||
306 | * @param connection connection to close with error | ||
307 | * @param emsg error message (can be NULL) | ||
302 | */ | 308 | */ |
303 | static void | 309 | static void |
304 | connection_close_error (struct MHD_Connection *connection) | 310 | connection_close_error (struct MHD_Connection *connection, |
311 | const char *emsg) | ||
305 | { | 312 | { |
313 | #if HAVE_MESSAGES | ||
314 | if (NULL != emsg) | ||
315 | MHD_DLOG (connection->daemon, emsg); | ||
316 | #endif | ||
306 | MHD_connection_close (connection, MHD_REQUEST_TERMINATED_WITH_ERROR); | 317 | MHD_connection_close (connection, MHD_REQUEST_TERMINATED_WITH_ERROR); |
307 | } | 318 | } |
308 | 319 | ||
309 | 320 | ||
310 | /** | 321 | /** |
322 | * Macro to only include error message in call to | ||
323 | * "connection_close_error" if we have HAVE_MESSAGES. | ||
324 | */ | ||
325 | #if HAVE_MESSAGES | ||
326 | #define CONNECTION_CLOSE_ERROR(c, emsg) connection_close_error (c, emsg) | ||
327 | #else | ||
328 | #define CONNECTION_CLOSE_ERROR(c, emsg) connection_close_error (c, NULL) | ||
329 | #endif | ||
330 | |||
331 | |||
332 | /** | ||
311 | * Prepare the response buffer of this connection for | 333 | * Prepare the response buffer of this connection for |
312 | * sending. Assumes that the response mutex is | 334 | * sending. Assumes that the response mutex is |
313 | * already held. If the transmission is complete, | 335 | * already held. If the transmission is complete, |
@@ -357,16 +379,12 @@ try_ready_normal_body (struct MHD_Connection *connection) | |||
357 | if ( (ret == MHD_CONTENT_READER_END_OF_STREAM) || | 379 | if ( (ret == MHD_CONTENT_READER_END_OF_STREAM) || |
358 | (ret == MHD_CONTENT_READER_END_WITH_ERROR) ) | 380 | (ret == MHD_CONTENT_READER_END_WITH_ERROR) ) |
359 | { | 381 | { |
360 | /* either error or http 1.0 transfer, close | 382 | /* either error or http 1.0 transfer, close socket! */ |
361 | socket! */ | ||
362 | #if DEBUG_CLOSE | ||
363 | #if HAVE_MESSAGES | ||
364 | MHD_DLOG (connection->daemon, | ||
365 | "Closing connection (end of response or error)\n"); | ||
366 | #endif | ||
367 | #endif | ||
368 | response->total_size = connection->response_write_position; | 383 | response->total_size = connection->response_write_position; |
369 | connection_close_error (connection); | 384 | CONNECTION_CLOSE_ERROR (connection, |
385 | (ret == MHD_CONTENT_READER_END_OF_STREAM) | ||
386 | ? "Closing connection (end of response)\n" | ||
387 | : "Closing connection (stream error)\n"); | ||
370 | return MHD_NO; | 388 | return MHD_NO; |
371 | } | 389 | } |
372 | response->data_start = connection->response_write_position; | 390 | response->data_start = connection->response_write_position; |
@@ -405,13 +423,8 @@ try_ready_chunked_body (struct MHD_Connection *connection) | |||
405 | if (size < 128) | 423 | if (size < 128) |
406 | { | 424 | { |
407 | /* not enough memory */ | 425 | /* not enough memory */ |
408 | #if DEBUG_CLOSE | 426 | CONNECTION_CLOSE_ERROR (connection, |
409 | #if HAVE_MESSAGES | 427 | "Closing connection (out of memory)\n"); |
410 | MHD_DLOG (connection->daemon, | ||
411 | "Closing connection (out of memory)\n"); | ||
412 | #endif | ||
413 | #endif | ||
414 | connection_close_error (connection); | ||
415 | return MHD_NO; | 428 | return MHD_NO; |
416 | } | 429 | } |
417 | buf = MHD_pool_allocate (connection->pool, size, MHD_NO); | 430 | buf = MHD_pool_allocate (connection->pool, size, MHD_NO); |
@@ -445,14 +458,9 @@ try_ready_chunked_body (struct MHD_Connection *connection) | |||
445 | if (ret == MHD_CONTENT_READER_END_WITH_ERROR) | 458 | if (ret == MHD_CONTENT_READER_END_WITH_ERROR) |
446 | { | 459 | { |
447 | /* error, close socket! */ | 460 | /* error, close socket! */ |
448 | #if DEBUG_CLOSE | ||
449 | #if HAVE_MESSAGES | ||
450 | MHD_DLOG (connection->daemon, | ||
451 | "Closing connection (error generating response)\n"); | ||
452 | #endif | ||
453 | #endif | ||
454 | response->total_size = connection->response_write_position; | 461 | response->total_size = connection->response_write_position; |
455 | connection_close_error (connection); | 462 | CONNECTION_CLOSE_ERROR (connection, |
463 | "Closing connection (error generating response)\n"); | ||
456 | return MHD_NO; | 464 | return MHD_NO; |
457 | } | 465 | } |
458 | if (ret == MHD_CONTENT_READER_END_OF_STREAM) | 466 | if (ret == MHD_CONTENT_READER_END_OF_STREAM) |
@@ -722,11 +730,8 @@ transmit_error_response (struct MHD_Connection *connection, | |||
722 | if (MHD_NO == build_header_response (connection)) | 730 | if (MHD_NO == build_header_response (connection)) |
723 | { | 731 | { |
724 | /* oops - close! */ | 732 | /* oops - close! */ |
725 | #if HAVE_MESSAGES | 733 | CONNECTION_CLOSE_ERROR (connection, |
726 | MHD_DLOG (connection->daemon, | 734 | "Closing connection (failed to create response header)\n"); |
727 | "Closing connection (failed to create response header)\n"); | ||
728 | #endif | ||
729 | connection->state = MHD_CONNECTION_CLOSED; | ||
730 | } | 735 | } |
731 | else | 736 | else |
732 | { | 737 | { |
@@ -788,11 +793,9 @@ MHD_connection_get_pollfd (struct MHD_Connection *connection, struct MHD_Pollfd | |||
788 | connection->pool = MHD_pool_create (connection->daemon->pool_size); | 793 | connection->pool = MHD_pool_create (connection->daemon->pool_size); |
789 | if (connection->pool == NULL) | 794 | if (connection->pool == NULL) |
790 | { | 795 | { |
791 | #if HAVE_MESSAGES | 796 | CONNECTION_CLOSE_ERROR (connection, |
792 | MHD_DLOG (connection->daemon, "Failed to create memory pool!\n"); | 797 | "Failed to create memory pool!\n"); |
793 | #endif | 798 | return MHD_YES; |
794 | connection_close_error (connection); | ||
795 | return MHD_NO; | ||
796 | } | 799 | } |
797 | fd = connection->socket_fd; | 800 | fd = connection->socket_fd; |
798 | p->fd = fd; | 801 | p->fd = fd; |
@@ -822,7 +825,8 @@ MHD_connection_get_pollfd (struct MHD_Connection *connection, struct MHD_Pollfd | |||
822 | if ((connection->read_closed) && | 825 | if ((connection->read_closed) && |
823 | (connection->read_buffer_offset == 0)) | 826 | (connection->read_buffer_offset == 0)) |
824 | { | 827 | { |
825 | connection->state = MHD_CONNECTION_CLOSED; | 828 | CONNECTION_CLOSE_ERROR (connection, |
829 | "Connection buffer to small for request\n"); | ||
826 | continue; | 830 | continue; |
827 | } | 831 | } |
828 | if ((connection->read_buffer_offset == connection->read_buffer_size) | 832 | if ((connection->read_buffer_offset == connection->read_buffer_size) |
@@ -883,7 +887,8 @@ MHD_connection_get_pollfd (struct MHD_Connection *connection, struct MHD_Pollfd | |||
883 | read buffer if needed, no size-check required */ | 887 | read buffer if needed, no size-check required */ |
884 | if (MHD_YES == connection->read_closed) | 888 | if (MHD_YES == connection->read_closed) |
885 | { | 889 | { |
886 | connection->state = MHD_CONNECTION_CLOSED; | 890 | CONNECTION_CLOSE_ERROR (connection, |
891 | "Connection closed while reading request\n"); | ||
887 | continue; | 892 | continue; |
888 | } | 893 | } |
889 | p->events |= MHD_POLL_ACTION_IN; | 894 | p->events |= MHD_POLL_ACTION_IN; |
@@ -923,10 +928,7 @@ MHD_connection_get_pollfd (struct MHD_Connection *connection, struct MHD_Pollfd | |||
923 | EXTRA_CHECK (0); | 928 | EXTRA_CHECK (0); |
924 | break; | 929 | break; |
925 | case MHD_CONNECTION_CLOSED: | 930 | case MHD_CONNECTION_CLOSED: |
926 | if (connection->socket_fd != -1) | ||
927 | connection_close_error (connection); | ||
928 | return MHD_YES; /* do nothing, not even reading */ | 931 | return MHD_YES; /* do nothing, not even reading */ |
929 | |||
930 | default: | 932 | default: |
931 | EXTRA_CHECK (0); | 933 | EXTRA_CHECK (0); |
932 | } | 934 | } |
@@ -1227,11 +1229,8 @@ call_connection_handler (struct MHD_Connection *connection) | |||
1227 | &connection->client_context)) | 1229 | &connection->client_context)) |
1228 | { | 1230 | { |
1229 | /* serious internal error, close connection */ | 1231 | /* serious internal error, close connection */ |
1230 | #if HAVE_MESSAGES | 1232 | CONNECTION_CLOSE_ERROR (connection, |
1231 | MHD_DLOG (connection->daemon, | 1233 | "Internal application error, closing connection.\n"); |
1232 | "Internal application error, closing connection.\n"); | ||
1233 | #endif | ||
1234 | connection_close_error (connection); | ||
1235 | return; | 1234 | return; |
1236 | } | 1235 | } |
1237 | } | 1236 | } |
@@ -1279,11 +1278,8 @@ process_request_body (struct MHD_Connection *connection) | |||
1279 | if (i == 0) | 1278 | if (i == 0) |
1280 | { | 1279 | { |
1281 | /* malformed encoding */ | 1280 | /* malformed encoding */ |
1282 | #if HAVE_MESSAGES | 1281 | CONNECTION_CLOSE_ERROR (connection, |
1283 | MHD_DLOG (connection->daemon, | 1282 | "Received malformed HTTP request (bad chunked encoding), closing connection.\n"); |
1284 | "Received malformed HTTP request (bad chunked encoding), closing connection.\n"); | ||
1285 | #endif | ||
1286 | connection_close_error (connection); | ||
1287 | return; | 1283 | return; |
1288 | } | 1284 | } |
1289 | available -= i; | 1285 | available -= i; |
@@ -1334,11 +1330,8 @@ process_request_body (struct MHD_Connection *connection) | |||
1334 | if (malformed) | 1330 | if (malformed) |
1335 | { | 1331 | { |
1336 | /* malformed encoding */ | 1332 | /* malformed encoding */ |
1337 | #if HAVE_MESSAGES | 1333 | CONNECTION_CLOSE_ERROR (connection, |
1338 | MHD_DLOG (connection->daemon, | 1334 | "Received malformed HTTP request (bad chunked encoding), closing connection.\n"); |
1339 | "Received malformed HTTP request (bad chunked encoding), closing connection.\n"); | ||
1340 | #endif | ||
1341 | connection_close_error (connection); | ||
1342 | return; | 1335 | return; |
1343 | } | 1336 | } |
1344 | i++; | 1337 | i++; |
@@ -1390,11 +1383,8 @@ process_request_body (struct MHD_Connection *connection) | |||
1390 | &connection->client_context)) | 1383 | &connection->client_context)) |
1391 | { | 1384 | { |
1392 | /* serious internal error, close connection */ | 1385 | /* serious internal error, close connection */ |
1393 | #if HAVE_MESSAGES | 1386 | CONNECTION_CLOSE_ERROR (connection, |
1394 | MHD_DLOG (connection->daemon, | 1387 | "Internal application error, closing connection.\n"); |
1395 | "Internal application error, closing connection.\n"); | ||
1396 | #endif | ||
1397 | connection_close_error (connection); | ||
1398 | return; | 1388 | return; |
1399 | } | 1389 | } |
1400 | if (processed > used) | 1390 | if (processed > used) |
@@ -1458,7 +1448,7 @@ do_read (struct MHD_Connection *connection) | |||
1458 | MHD_DLOG (connection->daemon, | 1448 | MHD_DLOG (connection->daemon, |
1459 | "Failed to receive data: %s\n", STRERROR (errno)); | 1449 | "Failed to receive data: %s\n", STRERROR (errno)); |
1460 | #endif | 1450 | #endif |
1461 | connection_close_error (connection); | 1451 | CONNECTION_CLOSE_ERROR (connection, NULL); |
1462 | return MHD_YES; | 1452 | return MHD_YES; |
1463 | } | 1453 | } |
1464 | if (bytes_read == 0) | 1454 | if (bytes_read == 0) |
@@ -1505,7 +1495,7 @@ do_write (struct MHD_Connection *connection) | |||
1505 | MHD_DLOG (connection->daemon, | 1495 | MHD_DLOG (connection->daemon, |
1506 | "Failed to send data: %s\n", STRERROR (errno)); | 1496 | "Failed to send data: %s\n", STRERROR (errno)); |
1507 | #endif | 1497 | #endif |
1508 | connection_close_error (connection); | 1498 | CONNECTION_CLOSE_ERROR (connection, NULL); |
1509 | return MHD_YES; | 1499 | return MHD_YES; |
1510 | } | 1500 | } |
1511 | #if DEBUG_SEND_DATA | 1501 | #if DEBUG_SEND_DATA |
@@ -1555,11 +1545,8 @@ process_header_line (struct MHD_Connection *connection, char *line) | |||
1555 | if (colon == NULL) | 1545 | if (colon == NULL) |
1556 | { | 1546 | { |
1557 | /* error in header line, die hard */ | 1547 | /* error in header line, die hard */ |
1558 | #if HAVE_MESSAGES | 1548 | CONNECTION_CLOSE_ERROR (connection, |
1559 | MHD_DLOG (connection->daemon, | 1549 | "Received malformed line (no colon), closing connection.\n"); |
1560 | "Received malformed line (no colon), closing connection.\n"); | ||
1561 | #endif | ||
1562 | connection->state = MHD_CONNECTION_CLOSED; | ||
1563 | return MHD_NO; | 1550 | return MHD_NO; |
1564 | } | 1551 | } |
1565 | /* zero-terminate header */ | 1552 | /* zero-terminate header */ |
@@ -1696,7 +1683,7 @@ parse_connection_headers (struct MHD_Connection *connection) | |||
1696 | "Failed to parse `%s' header `%s', closing connection.\n", | 1683 | "Failed to parse `%s' header `%s', closing connection.\n", |
1697 | MHD_HTTP_HEADER_CONTENT_LENGTH, clen); | 1684 | MHD_HTTP_HEADER_CONTENT_LENGTH, clen); |
1698 | #endif | 1685 | #endif |
1699 | connection->state = MHD_CONNECTION_CLOSED; | 1686 | CONNECTION_CLOSE_ERROR (connection, NULL); |
1700 | return; | 1687 | return; |
1701 | } | 1688 | } |
1702 | connection->remaining_upload_size = cval; | 1689 | connection->remaining_upload_size = cval; |
@@ -1726,15 +1713,15 @@ parse_connection_headers (struct MHD_Connection *connection) | |||
1726 | * implementations (multithreaded, external select, internal select) | 1713 | * implementations (multithreaded, external select, internal select) |
1727 | * call this function to handle reads. | 1714 | * call this function to handle reads. |
1728 | * | 1715 | * |
1729 | * @return MHD_YES if we should continue to process the | 1716 | * @return always MHD_YES (we should continue to process the |
1730 | * connection (not dead yet), MHD_NO if it died | 1717 | * connection) |
1731 | */ | 1718 | */ |
1732 | int | 1719 | int |
1733 | MHD_connection_handle_read (struct MHD_Connection *connection) | 1720 | MHD_connection_handle_read (struct MHD_Connection *connection) |
1734 | { | 1721 | { |
1735 | connection->last_activity = time (NULL); | 1722 | connection->last_activity = time (NULL); |
1736 | if (connection->state == MHD_CONNECTION_CLOSED) | 1723 | if (connection->state == MHD_CONNECTION_CLOSED) |
1737 | return MHD_NO; | 1724 | return MHD_YES; |
1738 | /* make sure "read" has a reasonable number of bytes | 1725 | /* make sure "read" has a reasonable number of bytes |
1739 | in buffer to use per system call (if possible) */ | 1726 | in buffer to use per system call (if possible) */ |
1740 | if (connection->read_buffer_offset + MHD_BUF_INC_SIZE > | 1727 | if (connection->read_buffer_offset + MHD_BUF_INC_SIZE > |
@@ -1767,9 +1754,7 @@ MHD_connection_handle_read (struct MHD_Connection *connection) | |||
1767 | } | 1754 | } |
1768 | break; | 1755 | break; |
1769 | case MHD_CONNECTION_CLOSED: | 1756 | case MHD_CONNECTION_CLOSED: |
1770 | if (connection->socket_fd != -1) | 1757 | return MHD_YES; |
1771 | connection_close_error (connection); | ||
1772 | return MHD_NO; | ||
1773 | default: | 1758 | default: |
1774 | /* shrink read buffer to how much is actually used */ | 1759 | /* shrink read buffer to how much is actually used */ |
1775 | MHD_pool_reallocate (connection->pool, | 1760 | MHD_pool_reallocate (connection->pool, |
@@ -1783,14 +1768,15 @@ MHD_connection_handle_read (struct MHD_Connection *connection) | |||
1783 | return MHD_YES; | 1768 | return MHD_YES; |
1784 | } | 1769 | } |
1785 | 1770 | ||
1771 | |||
1786 | /** | 1772 | /** |
1787 | * This function was created to handle writes to sockets when it has | 1773 | * This function was created to handle writes to sockets when it has |
1788 | * been determined that the socket can be written to. All | 1774 | * been determined that the socket can be written to. All |
1789 | * implementations (multithreaded, external select, internal select) | 1775 | * implementations (multithreaded, external select, internal select) |
1790 | * call this function | 1776 | * call this function |
1791 | * | 1777 | * |
1792 | * @return MHD_YES if we should continue to process the | 1778 | * @return always MHD_YES (we should continue to process the |
1793 | * connection (not dead yet), MHD_NO if it died | 1779 | * connection) |
1794 | */ | 1780 | */ |
1795 | int | 1781 | int |
1796 | MHD_connection_handle_write (struct MHD_Connection *connection) | 1782 | MHD_connection_handle_write (struct MHD_Connection *connection) |
@@ -1828,8 +1814,8 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
1828 | MHD_DLOG (connection->daemon, | 1814 | MHD_DLOG (connection->daemon, |
1829 | "Failed to send data: %s\n", STRERROR (errno)); | 1815 | "Failed to send data: %s\n", STRERROR (errno)); |
1830 | #endif | 1816 | #endif |
1831 | connection_close_error (connection); | 1817 | CONNECTION_CLOSE_ERROR (connection, NULL); |
1832 | return MHD_NO; | 1818 | return MHD_YES; |
1833 | } | 1819 | } |
1834 | #if DEBUG_SEND_DATA | 1820 | #if DEBUG_SEND_DATA |
1835 | FPRINTF (stderr, | 1821 | FPRINTF (stderr, |
@@ -1889,8 +1875,8 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
1889 | MHD_DLOG (connection->daemon, | 1875 | MHD_DLOG (connection->daemon, |
1890 | "Failed to send data: %s\n", STRERROR (errno)); | 1876 | "Failed to send data: %s\n", STRERROR (errno)); |
1891 | #endif | 1877 | #endif |
1892 | connection_close_error (connection); | 1878 | CONNECTION_CLOSE_ERROR (connection, NULL); |
1893 | return MHD_NO; | 1879 | return MHD_YES; |
1894 | } | 1880 | } |
1895 | connection->response_write_position += ret; | 1881 | connection->response_write_position += ret; |
1896 | if (connection->response_write_position == | 1882 | if (connection->response_write_position == |
@@ -1920,16 +1906,14 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
1920 | EXTRA_CHECK (0); | 1906 | EXTRA_CHECK (0); |
1921 | break; | 1907 | break; |
1922 | case MHD_CONNECTION_CLOSED: | 1908 | case MHD_CONNECTION_CLOSED: |
1923 | if (connection->socket_fd != -1) | 1909 | return MHD_YES; |
1924 | connection_close_error (connection); | ||
1925 | return MHD_NO; | ||
1926 | case MHD_TLS_CONNECTION_INIT: | 1910 | case MHD_TLS_CONNECTION_INIT: |
1927 | EXTRA_CHECK (0); | 1911 | EXTRA_CHECK (0); |
1928 | break; | 1912 | break; |
1929 | default: | 1913 | default: |
1930 | EXTRA_CHECK (0); | 1914 | EXTRA_CHECK (0); |
1931 | connection_close_error (connection); | 1915 | CONNECTION_CLOSE_ERROR (connection, "Internal error\n"); |
1932 | return MHD_NO; | 1916 | return MHD_YES; |
1933 | } | 1917 | } |
1934 | break; | 1918 | break; |
1935 | } | 1919 | } |
@@ -1948,6 +1932,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
1948 | int | 1932 | int |
1949 | MHD_connection_handle_idle (struct MHD_Connection *connection) | 1933 | MHD_connection_handle_idle (struct MHD_Connection *connection) |
1950 | { | 1934 | { |
1935 | struct MHD_Daemon *daemon; | ||
1951 | unsigned int timeout; | 1936 | unsigned int timeout; |
1952 | const char *end; | 1937 | const char *end; |
1953 | char *line; | 1938 | char *line; |
@@ -1968,13 +1953,14 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
1968 | continue; | 1953 | continue; |
1969 | if (connection->read_closed) | 1954 | if (connection->read_closed) |
1970 | { | 1955 | { |
1971 | connection->state = MHD_CONNECTION_CLOSED; | 1956 | CONNECTION_CLOSE_ERROR (connection, |
1957 | "Connection closed while reading request\n"); | ||
1972 | continue; | 1958 | continue; |
1973 | } | 1959 | } |
1974 | break; | 1960 | break; |
1975 | } | 1961 | } |
1976 | if (MHD_NO == parse_initial_message_line (connection, line)) | 1962 | if (MHD_NO == parse_initial_message_line (connection, line)) |
1977 | connection->state = MHD_CONNECTION_CLOSED; | 1963 | CONNECTION_CLOSE_ERROR (connection, NULL); |
1978 | else | 1964 | else |
1979 | connection->state = MHD_CONNECTION_URL_RECEIVED; | 1965 | connection->state = MHD_CONNECTION_URL_RECEIVED; |
1980 | continue; | 1966 | continue; |
@@ -1986,7 +1972,8 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
1986 | continue; | 1972 | continue; |
1987 | if (connection->read_closed) | 1973 | if (connection->read_closed) |
1988 | { | 1974 | { |
1989 | connection->state = MHD_CONNECTION_CLOSED; | 1975 | CONNECTION_CLOSE_ERROR (connection, |
1976 | "Connection closed while reading request\n"); | ||
1990 | continue; | 1977 | continue; |
1991 | } | 1978 | } |
1992 | break; | 1979 | break; |
@@ -2013,7 +2000,8 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
2013 | continue; | 2000 | continue; |
2014 | if (connection->read_closed) | 2001 | if (connection->read_closed) |
2015 | { | 2002 | { |
2016 | connection->state = MHD_CONNECTION_CLOSED; | 2003 | CONNECTION_CLOSE_ERROR (connection, |
2004 | "Connection closed while reading request\n"); | ||
2017 | continue; | 2005 | continue; |
2018 | } | 2006 | } |
2019 | break; | 2007 | break; |
@@ -2088,7 +2076,8 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
2088 | continue; | 2076 | continue; |
2089 | if (connection->read_closed) | 2077 | if (connection->read_closed) |
2090 | { | 2078 | { |
2091 | connection->state = MHD_CONNECTION_CLOSED; | 2079 | CONNECTION_CLOSE_ERROR (connection, |
2080 | "Connection closed while reading request\n"); | ||
2092 | continue; | 2081 | continue; |
2093 | } | 2082 | } |
2094 | break; | 2083 | break; |
@@ -2115,7 +2104,8 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
2115 | continue; | 2104 | continue; |
2116 | if (connection->read_closed) | 2105 | if (connection->read_closed) |
2117 | { | 2106 | { |
2118 | connection->state = MHD_CONNECTION_CLOSED; | 2107 | CONNECTION_CLOSE_ERROR (connection, |
2108 | "Connection closed while reading request\n"); | ||
2119 | continue; | 2109 | continue; |
2120 | } | 2110 | } |
2121 | break; | 2111 | break; |
@@ -2138,11 +2128,8 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
2138 | if (MHD_NO == build_header_response (connection)) | 2128 | if (MHD_NO == build_header_response (connection)) |
2139 | { | 2129 | { |
2140 | /* oops - close! */ | 2130 | /* oops - close! */ |
2141 | #if HAVE_MESSAGES | 2131 | CONNECTION_CLOSE_ERROR (connection, |
2142 | MHD_DLOG (connection->daemon, | 2132 | "Closing connection (failed to create response header)\n"); |
2143 | "Closing connection (failed to create response header)\n"); | ||
2144 | #endif | ||
2145 | connection->state = MHD_CONNECTION_CLOSED; | ||
2146 | continue; | 2133 | continue; |
2147 | } | 2134 | } |
2148 | connection->state = MHD_CONNECTION_HEADERS_SENDING; | 2135 | connection->state = MHD_CONNECTION_HEADERS_SENDING; |
@@ -2253,7 +2240,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
2253 | (0 != strcasecmp (MHD_HTTP_VERSION_1_1, connection->version))) | 2240 | (0 != strcasecmp (MHD_HTTP_VERSION_1_1, connection->version))) |
2254 | { | 2241 | { |
2255 | /* http 1.0, version-less requests cannot be pipelined */ | 2242 | /* http 1.0, version-less requests cannot be pipelined */ |
2256 | connection->state = MHD_CONNECTION_CLOSED; | 2243 | MHD_connection_close (connection, MHD_REQUEST_TERMINATED_COMPLETED_OK); |
2257 | MHD_pool_destroy (connection->pool); | 2244 | MHD_pool_destroy (connection->pool); |
2258 | connection->pool = NULL; | 2245 | connection->pool = NULL; |
2259 | connection->read_buffer = NULL; | 2246 | connection->read_buffer = NULL; |
@@ -2271,9 +2258,28 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
2271 | } | 2258 | } |
2272 | continue; | 2259 | continue; |
2273 | case MHD_CONNECTION_CLOSED: | 2260 | case MHD_CONNECTION_CLOSED: |
2274 | if (connection->socket_fd != -1) | 2261 | daemon = connection->daemon; |
2275 | connection_close_error (connection); | 2262 | DLL_remove (daemon->connections_head, |
2276 | break; | 2263 | daemon->connections_tail, |
2264 | connection); | ||
2265 | if (0 != pthread_mutex_lock(&daemon->cleanup_connection_mutex)) | ||
2266 | { | ||
2267 | #if HAVE_MESSAGES | ||
2268 | MHD_DLOG (daemon, "Failed to acquire cleanup mutex\n"); | ||
2269 | #endif | ||
2270 | abort(); | ||
2271 | } | ||
2272 | DLL_insert (daemon->cleanup_head, | ||
2273 | daemon->cleanup_tail, | ||
2274 | connection); | ||
2275 | if (0 != pthread_mutex_unlock(&daemon->cleanup_connection_mutex)) | ||
2276 | { | ||
2277 | #if HAVE_MESSAGES | ||
2278 | MHD_DLOG (daemon, "Failed to release cleanup mutex\n"); | ||
2279 | #endif | ||
2280 | abort(); | ||
2281 | } | ||
2282 | return MHD_NO; | ||
2277 | default: | 2283 | default: |
2278 | EXTRA_CHECK (0); | 2284 | EXTRA_CHECK (0); |
2279 | break; | 2285 | break; |
@@ -2281,12 +2287,11 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
2281 | break; | 2287 | break; |
2282 | } | 2288 | } |
2283 | timeout = connection->daemon->connection_timeout; | 2289 | timeout = connection->daemon->connection_timeout; |
2284 | if ((connection->socket_fd != -1) && | 2290 | if ( (timeout != 0) && |
2285 | (timeout != 0) && | 2291 | (timeout <= (time (NULL) - connection->last_activity)) ) |
2286 | (timeout <= (time (NULL) - connection->last_activity)) ) | ||
2287 | { | 2292 | { |
2288 | MHD_connection_close (connection, MHD_REQUEST_TERMINATED_TIMEOUT_REACHED); | 2293 | MHD_connection_close (connection, MHD_REQUEST_TERMINATED_TIMEOUT_REACHED); |
2289 | return MHD_NO; | 2294 | return MHD_YES; |
2290 | } | 2295 | } |
2291 | return MHD_YES; | 2296 | return MHD_YES; |
2292 | } | 2297 | } |