aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2021-09-29 16:15:35 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2021-09-29 20:48:53 +0300
commitd7cac578837064baabe1284072be1ceb34dae23e (patch)
tree2d153ba75672f00d8c28e013e52bd37acf3b5c11 /src
parent0eb370643d71402cbfb2f33f9dba1f9b6d86473a (diff)
downloadlibmicrohttpd-d7cac578837064baabe1284072be1ceb34dae23e.tar.gz
libmicrohttpd-d7cac578837064baabe1284072be1ceb34dae23e.zip
connection_maximize_write_buffer(): don't try to grow if no space is available
Diffstat (limited to 'src')
-rw-r--r--src/microhttpd/connection.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 3ca4d4a3..3e6a4ba0 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -1523,27 +1523,32 @@ connection_maximize_write_buffer (struct MHD_Connection *connection)
1523 struct MemoryPool *const pool = connection->pool; 1523 struct MemoryPool *const pool = connection->pool;
1524 void *new_buf; 1524 void *new_buf;
1525 size_t new_size; 1525 size_t new_size;
1526 size_t free_size;
1526 1527
1527 mhd_assert ((NULL != c->write_buffer) || (0 == c->write_buffer_size)); 1528 mhd_assert ((NULL != c->write_buffer) || (0 == c->write_buffer_size));
1528 mhd_assert (c->write_buffer_append_offset >= c->write_buffer_send_offset); 1529 mhd_assert (c->write_buffer_append_offset >= c->write_buffer_send_offset);
1529 mhd_assert (c->write_buffer_size >= c->write_buffer_append_offset); 1530 mhd_assert (c->write_buffer_size >= c->write_buffer_append_offset);
1530 1531
1531 new_size = c->write_buffer_size + MHD_pool_get_free (pool); 1532 free_size = MHD_pool_get_free (pool);
1532 new_buf = MHD_pool_reallocate (pool, 1533 if (0 != free_size)
1533 c->write_buffer,
1534 c->write_buffer_size,
1535 new_size);
1536 /* Buffer position must not be moved.
1537 * Position could be moved only if buffer was allocated 'from_end',
1538 * which cannot happen. */
1539 mhd_assert ((c->write_buffer == new_buf) || (NULL == c->write_buffer));
1540 c->write_buffer = new_buf;
1541 c->write_buffer_size = new_size;
1542 if (c->write_buffer_send_offset == c->write_buffer_append_offset)
1543 { 1534 {
1544 /* All data have been sent, reset offsets to zero. */ 1535 new_size = c->write_buffer_size + free_size;
1545 c->write_buffer_send_offset = 0; 1536 new_buf = MHD_pool_reallocate (pool,
1546 c->write_buffer_append_offset = 0; 1537 c->write_buffer,
1538 c->write_buffer_size,
1539 new_size);
1540 /* Buffer position must not be moved.
1541 * Position could be moved only if buffer was allocated 'from_end',
1542 * which cannot happen. */
1543 mhd_assert ((c->write_buffer == new_buf) || (NULL == c->write_buffer));
1544 c->write_buffer = new_buf;
1545 c->write_buffer_size = new_size;
1546 if (c->write_buffer_send_offset == c->write_buffer_append_offset)
1547 {
1548 /* All data have been sent, reset offsets to zero. */
1549 c->write_buffer_send_offset = 0;
1550 c->write_buffer_append_offset = 0;
1551 }
1547 } 1552 }
1548 1553
1549 return c->write_buffer_size - c->write_buffer_append_offset; 1554 return c->write_buffer_size - c->write_buffer_append_offset;