diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-11-06 21:56:46 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-11-06 21:56:46 +0000 |
commit | 3ed1e8de9ffabbcbe8c6c6ee5db1802d3f989e71 (patch) | |
tree | 0bfc8a69948debaae8642d0f4de580e15145dc83 /src/microhttpd | |
parent | fcb0a20d91344e558b80a487f9d945695b61d66d (diff) | |
download | libmicrohttpd-3ed1e8de9ffabbcbe8c6c6ee5db1802d3f989e71.tar.gz libmicrohttpd-3ed1e8de9ffabbcbe8c6c6ee5db1802d3f989e71.zip |
-fix shrinkage
Diffstat (limited to 'src/microhttpd')
-rw-r--r-- | src/microhttpd/connection.c | 11 | ||||
-rw-r--r-- | src/microhttpd/memorypool.c | 25 | ||||
-rw-r--r-- | src/microhttpd/memorypool.h | 13 |
3 files changed, 32 insertions, 17 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index 27dac309..a7d949c0 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -2559,14 +2559,15 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
2559 | /* can try to keep-alive */ | 2559 | /* can try to keep-alive */ |
2560 | connection->version = NULL; | 2560 | connection->version = NULL; |
2561 | connection->state = MHD_CONNECTION_INIT; | 2561 | connection->state = MHD_CONNECTION_INIT; |
2562 | /* read_buffer_size is correct here, as we want to | 2562 | /* Reset the read buffer to the starting size, |
2563 | preserve the entire read buffer allocation, even | 2563 | preserving the bytes we have already read. */ |
2564 | if in terms of the data we only care to preserve | ||
2565 | up to "read_buffer_offset" */ | ||
2566 | connection->read_buffer | 2564 | connection->read_buffer |
2567 | = MHD_pool_reset (connection->pool, | 2565 | = MHD_pool_reset (connection->pool, |
2568 | connection->read_buffer, | 2566 | connection->read_buffer, |
2569 | connection->read_buffer_size); | 2567 | connection->read_buffer_offset, |
2568 | connection->daemon->pool_size / 2); | ||
2569 | connection->read_buffer_size | ||
2570 | = connection->daemon->pool_size / 2; | ||
2570 | } | 2571 | } |
2571 | connection->client_aware = MHD_NO; | 2572 | connection->client_aware = MHD_NO; |
2572 | connection->client_context = NULL; | 2573 | connection->client_context = NULL; |
diff --git a/src/microhttpd/memorypool.c b/src/microhttpd/memorypool.c index fab58006..c347c160 100644 --- a/src/microhttpd/memorypool.c +++ b/src/microhttpd/memorypool.c | |||
@@ -219,7 +219,8 @@ MHD_pool_reallocate (struct MemoryPool *pool, | |||
219 | if ((pool->end < old_size) || (pool->end < asize)) | 219 | if ((pool->end < old_size) || (pool->end < asize)) |
220 | return NULL; /* unsatisfiable or bogus request */ | 220 | return NULL; /* unsatisfiable or bogus request */ |
221 | 221 | ||
222 | if ((pool->pos >= old_size) && (&pool->memory[pool->pos - old_size] == old)) | 222 | if ( (pool->pos >= old_size) && |
223 | (&pool->memory[pool->pos - old_size] == old) ) | ||
223 | { | 224 | { |
224 | /* was the previous allocation - optimize! */ | 225 | /* was the previous allocation - optimize! */ |
225 | if (pool->pos + asize - old_size <= pool->end) | 226 | if (pool->pos + asize - old_size <= pool->end) |
@@ -251,32 +252,40 @@ MHD_pool_reallocate (struct MemoryPool *pool, | |||
251 | 252 | ||
252 | /** | 253 | /** |
253 | * Clear all entries from the memory pool except | 254 | * Clear all entries from the memory pool except |
254 | * for @a keep of the given @a size. | 255 | * for @a keep of the given @a size. The pointer |
256 | * returned should be a buffer of @a new_size where | ||
257 | * the first @a copy_bytes are from @a keep. | ||
255 | * | 258 | * |
256 | * @param pool memory pool to use for the operation | 259 | * @param pool memory pool to use for the operation |
257 | * @param keep pointer to the entry to keep (maybe NULL) | 260 | * @param keep pointer to the entry to keep (maybe NULL) |
258 | * @param size how many bytes need to be kept at this address | 261 | * @param copy_bytes how many bytes need to be kept at this address |
262 | * @param new_size how many bytes should the allocation we return have? | ||
263 | * (should be larger or equal to @a copy_bytes) | ||
259 | * @return addr new address of @a keep (if it had to change) | 264 | * @return addr new address of @a keep (if it had to change) |
260 | */ | 265 | */ |
261 | void * | 266 | void * |
262 | MHD_pool_reset (struct MemoryPool *pool, | 267 | MHD_pool_reset (struct MemoryPool *pool, |
263 | void *keep, | 268 | void *keep, |
264 | size_t size) | 269 | size_t copy_bytes, |
270 | size_t new_size) | ||
265 | { | 271 | { |
266 | if (NULL != keep) | 272 | if (NULL != keep) |
267 | { | 273 | { |
268 | if (keep != pool->memory) | 274 | if (keep != pool->memory) |
269 | { | 275 | { |
270 | memmove (pool->memory, keep, size); | 276 | memmove (pool->memory, |
277 | keep, | ||
278 | copy_bytes); | ||
271 | keep = pool->memory; | 279 | keep = pool->memory; |
272 | } | 280 | } |
273 | } | 281 | } |
274 | pool->end = pool->size; | 282 | pool->end = pool->size; |
275 | memset (&pool->memory[size], | 283 | /* technically not needed, but safer to zero out */ |
284 | memset (&pool->memory[copy_bytes], | ||
276 | 0, | 285 | 0, |
277 | pool->size - size); | 286 | pool->size - copy_bytes); |
278 | if (NULL != keep) | 287 | if (NULL != keep) |
279 | pool->pos = ROUND_TO_ALIGN(size); | 288 | pool->pos = ROUND_TO_ALIGN (new_size); |
280 | return keep; | 289 | return keep; |
281 | } | 290 | } |
282 | 291 | ||
diff --git a/src/microhttpd/memorypool.h b/src/microhttpd/memorypool.h index 4868692d..647ac2c9 100644 --- a/src/microhttpd/memorypool.h +++ b/src/microhttpd/memorypool.h | |||
@@ -99,16 +99,21 @@ MHD_pool_reallocate (struct MemoryPool *pool, | |||
99 | 99 | ||
100 | /** | 100 | /** |
101 | * Clear all entries from the memory pool except | 101 | * Clear all entries from the memory pool except |
102 | * for "keep" of the given "size". | 102 | * for @a keep of the given @a copy_bytes. The pointer |
103 | * returned should be a buffer of @a new_size where | ||
104 | * the first @a copy_bytes are from @a keep. | ||
103 | * | 105 | * |
104 | * @param pool memory pool to use for the operation | 106 | * @param pool memory pool to use for the operation |
105 | * @param keep pointer to the entry to keep (maybe NULL) | 107 | * @param keep pointer to the entry to keep (maybe NULL) |
106 | * @param size how many bytes need to be kept at this address | 108 | * @param copy_bytes how many bytes need to be kept at this address |
107 | * @return addr new address of "keep" (if it had to change) | 109 | * @param new_size how many bytes should the allocation we return have? |
110 | * (should be larger or equal to @a copy_bytes) | ||
111 | * @return addr new address of @a keep (if it had to change) | ||
108 | */ | 112 | */ |
109 | void * | 113 | void * |
110 | MHD_pool_reset (struct MemoryPool *pool, | 114 | MHD_pool_reset (struct MemoryPool *pool, |
111 | void *keep, | 115 | void *keep, |
112 | size_t size); | 116 | size_t copy_bytes, |
117 | size_t new_size); | ||
113 | 118 | ||
114 | #endif | 119 | #endif |