[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libmicrohttpd] 28/29: try_grow_read_buffer(): better handling of edge c
From: |
gnunet |
Subject: |
[libmicrohttpd] 28/29: try_grow_read_buffer(): better handling of edge cases |
Date: |
Tue, 20 Jun 2023 22:24:41 +0200 |
This is an automated email from the git hooks/post-receive script.
karlson2k pushed a commit to branch master
in repository libmicrohttpd.
commit 8b17c9155fdac05273867ef5aab10d08b482bbee
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Mon Jun 19 18:25:05 2023 +0300
try_grow_read_buffer(): better handling of edge cases
Used application specified grow size instead of MHD default size.
When free space is becoming low first try to increase free space
to exact increment value before switching to "low memory" mode.
---
src/microhttpd/connection.c | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index db309bb8..d6c4ac1e 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -1768,6 +1768,7 @@ try_grow_read_buffer (struct MHD_Connection *connection,
{
size_t new_size;
size_t avail_size;
+ const size_t def_grow_size = connection->daemon->pool_increment;
void *rb;
avail_size = MHD_pool_get_free (connection->pool);
@@ -1780,14 +1781,23 @@ try_grow_read_buffer (struct MHD_Connection *connection,
size_t grow_size;
grow_size = avail_size / 8;
- if (MHD_BUF_INC_SIZE > grow_size)
+ if (def_grow_size > grow_size)
{ /* Shortage of space */
- if (! required)
- return false; /* Grow is not mandatory, leave some space in pool */
+ const size_t left_free =
+ connection->read_buffer_size - connection->read_buffer_offset;
+ mhd_assert (connection->read_buffer_size >= \
+ connection->read_buffer_offset);
+ if ((def_grow_size <= grow_size + left_free)
+ && (left_free < def_grow_size))
+ grow_size = def_grow_size - left_free; /* Use precise 'def_grow_size'
for new free space */
+ else if (! required)
+ return false; /* Grow is not mandatory,
leave some space in pool */
else
{
/* Shortage of space, but grow is mandatory */
- static const size_t small_inc = MHD_BUF_INC_SIZE / 8;
+ const size_t small_inc =
+ ((MHD_BUF_INC_SIZE > def_grow_size) ?
+ def_grow_size : MHD_BUF_INC_SIZE) / 8;
if (small_inc < avail_size)
grow_size = small_inc;
else
@@ -1821,6 +1831,7 @@ try_grow_read_buffer (struct MHD_Connection *connection,
mhd_assert (0);
return false;
}
+ mhd_assert (connection->read_buffer == rb);
connection->read_buffer = rb;
mhd_assert (NULL != connection->read_buffer);
connection->read_buffer_size = new_size;
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [libmicrohttpd] 22/29: Minor refactoring for partially processed request body, (continued)
- [libmicrohttpd] 22/29: Minor refactoring for partially processed request body, gnunet, 2023/06/20
- [libmicrohttpd] 14/29: Added test with folded header placed last, gnunet, 2023/06/20
- [libmicrohttpd] 15/29: Added test with large folded header, gnunet, 2023/06/20
- [libmicrohttpd] 20/29: Added checks for correct values specified for connection memory limits, gnunet, 2023/06/20
- [libmicrohttpd] 19/29: connection: fixed pipelined requests processing, gnunet, 2023/06/20
- [libmicrohttpd] 13/29: Added new tests with header fold, gnunet, 2023/06/20
- [libmicrohttpd] 18/29: Added proper connection's buffers pre-initialisaion, gnunet, 2023/06/20
- [libmicrohttpd] 17/29: connection.c: corrected error responses, gnunet, 2023/06/20
- [libmicrohttpd] 24/29: process new connection: fixed missing mutex unlock in error handling path, gnunet, 2023/06/20
- [libmicrohttpd] 23/29: Adjusted buffer increase default step size, gnunet, 2023/06/20
- [libmicrohttpd] 28/29: try_grow_read_buffer(): better handling of edge cases,
gnunet <=
- [libmicrohttpd] 26/29: W32 VS Projects: fixed code parsing, gnunet, 2023/06/20
- [libmicrohttpd] 27/29: Fixed some comments, gnunet, 2023/06/20
- [libmicrohttpd] 25/29: Fixed possible timeout value trim on 32-bits platforms, gnunet, 2023/06/20
- [libmicrohttpd] 29/29: Focused all read-buffer grows in a single point, related improvements., gnunet, 2023/06/20