diff options
Diffstat (limited to 'src/daemon/connection.c')
-rw-r--r-- | src/daemon/connection.c | 64 |
1 files changed, 37 insertions, 27 deletions
diff --git a/src/daemon/connection.c b/src/daemon/connection.c index 538ef97d..7b04a661 100644 --- a/src/daemon/connection.c +++ b/src/daemon/connection.c | |||
@@ -38,6 +38,15 @@ | |||
38 | #endif | 38 | #endif |
39 | 39 | ||
40 | /** | 40 | /** |
41 | * Minimum size by which MHD tries to increment read/write buffers. | ||
42 | * We usually begin with half the available pool space for the | ||
43 | * IO-buffer, but if absolutely needed we additively grow by the | ||
44 | * number of bytes given here (up to -- theoretically -- the full pool | ||
45 | * space). | ||
46 | */ | ||
47 | #define MHD_BUF_INC_SIZE 1024 | ||
48 | |||
49 | /** | ||
41 | * Message to transmit when http 1.1 request is received | 50 | * Message to transmit when http 1.1 request is received |
42 | */ | 51 | */ |
43 | #define HTTP_100_CONTINUE "HTTP/1.1 100 Continue\r\n\r\n" | 52 | #define HTTP_100_CONTINUE "HTTP/1.1 100 Continue\r\n\r\n" |
@@ -639,7 +648,12 @@ get_date_string (char *date) | |||
639 | 648 | ||
640 | 649 | ||
641 | /** | 650 | /** |
642 | * Try growing the read buffer | 651 | * Try growing the read buffer. We initially claim half the |
652 | * available buffer space for the read buffer (the other half | ||
653 | * being left for management data structures; the write | ||
654 | * buffer can in the end take virtually everything as the | ||
655 | * read buffer can be reduced to the minimum necessary at that | ||
656 | * point. | ||
643 | * | 657 | * |
644 | * @param connection the connection | 658 | * @param connection the connection |
645 | * @return MHD_YES on success, MHD_NO on failure | 659 | * @return MHD_YES on success, MHD_NO on failure |
@@ -648,18 +662,21 @@ static int | |||
648 | try_grow_read_buffer (struct MHD_Connection *connection) | 662 | try_grow_read_buffer (struct MHD_Connection *connection) |
649 | { | 663 | { |
650 | void *buf; | 664 | void *buf; |
665 | size_t new_size; | ||
651 | 666 | ||
667 | if (0 == connection->read_buffer_size) | ||
668 | new_size = connection->daemon->pool_size / 2; | ||
669 | else | ||
670 | new_size = connection->read_buffer_size + MHD_BUF_INC_SIZE; | ||
652 | buf = MHD_pool_reallocate (connection->pool, | 671 | buf = MHD_pool_reallocate (connection->pool, |
653 | connection->read_buffer, | 672 | connection->read_buffer, |
654 | connection->read_buffer_size, | 673 | connection->read_buffer_size, |
655 | connection->read_buffer_size * 2 + | 674 | new_size); |
656 | MHD_BUF_INC_SIZE + 1); | ||
657 | if (NULL == buf) | 675 | if (NULL == buf) |
658 | return MHD_NO; | 676 | return MHD_NO; |
659 | /* we can actually grow the buffer, do it! */ | 677 | /* we can actually grow the buffer, do it! */ |
660 | connection->read_buffer = buf; | 678 | connection->read_buffer = buf; |
661 | connection->read_buffer_size = | 679 | connection->read_buffer_size = new_size; |
662 | connection->read_buffer_size * 2 + MHD_BUF_INC_SIZE; | ||
663 | return MHD_YES; | 680 | return MHD_YES; |
664 | } | 681 | } |
665 | 682 | ||
@@ -1078,28 +1095,16 @@ get_next_header_line (struct MHD_Connection *connection) | |||
1078 | if (pos == connection->read_buffer_offset - 1) | 1095 | if (pos == connection->read_buffer_offset - 1) |
1079 | { | 1096 | { |
1080 | /* not found, consider growing... */ | 1097 | /* not found, consider growing... */ |
1081 | if (connection->read_buffer_offset == connection->read_buffer_size) | 1098 | if ( (connection->read_buffer_offset == connection->read_buffer_size) && |
1082 | { | 1099 | (MHD_NO == |
1083 | rbuf = MHD_pool_reallocate (connection->pool, | 1100 | try_grow_read_buffer (connection)) ) |
1084 | connection->read_buffer, | 1101 | { |
1085 | connection->read_buffer_size, | 1102 | transmit_error_response (connection, |
1086 | connection->read_buffer_size * 2 + | 1103 | (NULL != connection->url) |
1087 | MHD_BUF_INC_SIZE); | 1104 | ? MHD_HTTP_REQUEST_ENTITY_TOO_LARGE |
1088 | if (NULL == rbuf) | 1105 | : MHD_HTTP_REQUEST_URI_TOO_LONG, |
1089 | { | 1106 | REQUEST_TOO_BIG); |
1090 | transmit_error_response (connection, | 1107 | } |
1091 | (NULL != connection->url) | ||
1092 | ? MHD_HTTP_REQUEST_ENTITY_TOO_LARGE | ||
1093 | : MHD_HTTP_REQUEST_URI_TOO_LONG, | ||
1094 | REQUEST_TOO_BIG); | ||
1095 | } | ||
1096 | else | ||
1097 | { | ||
1098 | connection->read_buffer_size = | ||
1099 | connection->read_buffer_size * 2 + MHD_BUF_INC_SIZE; | ||
1100 | connection->read_buffer = rbuf; | ||
1101 | } | ||
1102 | } | ||
1103 | return NULL; | 1108 | return NULL; |
1104 | } | 1109 | } |
1105 | /* found, check if we have proper CRLF */ | 1110 | /* found, check if we have proper CRLF */ |
@@ -1581,6 +1586,7 @@ process_request_body (struct MHD_Connection *connection) | |||
1581 | connection->read_buffer_offset = available; | 1586 | connection->read_buffer_offset = available; |
1582 | } | 1587 | } |
1583 | 1588 | ||
1589 | |||
1584 | /** | 1590 | /** |
1585 | * Try reading data from the socket into the | 1591 | * Try reading data from the socket into the |
1586 | * read buffer of the connection. | 1592 | * read buffer of the connection. |
@@ -1681,6 +1687,9 @@ do_write (struct MHD_Connection *connection) | |||
1681 | /** | 1687 | /** |
1682 | * Check if we are done sending the write-buffer. | 1688 | * Check if we are done sending the write-buffer. |
1683 | * If so, transition into "next_state". | 1689 | * If so, transition into "next_state". |
1690 | * | ||
1691 | * @param connection connection to check write status for | ||
1692 | * @param next_state the next state to transition to | ||
1684 | * @return MHY_NO if we are not done, MHD_YES if we are | 1693 | * @return MHY_NO if we are not done, MHD_YES if we are |
1685 | */ | 1694 | */ |
1686 | static int | 1695 | static int |
@@ -1740,6 +1749,7 @@ process_header_line (struct MHD_Connection *connection, char *line) | |||
1740 | * Process a header value that spans multiple lines. | 1749 | * Process a header value that spans multiple lines. |
1741 | * The previous line(s) are in connection->last. | 1750 | * The previous line(s) are in connection->last. |
1742 | * | 1751 | * |
1752 | * @param connection connection we're processing | ||
1743 | * @param line the current input line | 1753 | * @param line the current input line |
1744 | * @param kind if the line is complete, add a header | 1754 | * @param kind if the line is complete, add a header |
1745 | * of the given kind | 1755 | * of the given kind |