From 2ccc281a69a056bc4fe72b829604037fa3792bfc Mon Sep 17 00:00:00 2001 From: "Evgeny Grin (Karlson2k)" Date: Fri, 4 Jun 2021 15:22:22 +0300 Subject: [PATCH] connection: handle large read-ahead situation --- src/microhttpd/connection.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index 321952eb..5038b378 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c @@ -3887,6 +3887,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) else { /* can try to keep-alive */ + size_t new_read_buf_size; connection->version = NULL; connection->http_ver = MHD_HTTP_VER_UNKNOWN; @@ -3897,13 +3898,16 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) connection->keepalive = MHD_CONN_KEEPALIVE_UNKOWN; /* Reset the read buffer to the starting size, preserving the bytes we have already read. */ + if (connection->read_buffer_offset > connection->daemon->pool_size / 2) + new_read_buf_size = connection->read_buffer_offset; + else + new_read_buf_size = connection->daemon->pool_size / 2; connection->read_buffer = MHD_pool_reset (connection->pool, connection->read_buffer, connection->read_buffer_offset, - connection->daemon->pool_size / 2); - connection->read_buffer_size - = connection->daemon->pool_size / 2; + new_read_buf_size); + connection->read_buffer_size = new_read_buf_size; } connection->client_context = NULL; connection->continue_message_write_offset = 0;