commit 4a4d659bac5040c7f7538e28535b4baaa1529ba8
parent 664d8ca99f681d6f222ec754f3f1d2943b78df7c
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date: Fri, 20 May 2022 13:09:59 +0300
connection_alloc_memory_(): made function non-static
Diffstat:
2 files changed, 23 insertions(+), 9 deletions(-)
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
@@ -242,9 +242,9 @@ str_conn_error_ (ssize_t mhd_err_code)
* @return pointer to allocated memory region in the pool or
* NULL if no memory is available
*/
-static void *
-connection_alloc_memory (struct MHD_Connection *connection,
- size_t size)
+void *
+MHD_connection_alloc_memory_ (struct MHD_Connection *connection,
+ size_t size)
{
struct MHD_Connection *const c = connection; /* a short alias */
struct MemoryPool *const pool = c->pool; /* a short alias */
@@ -482,8 +482,8 @@ MHD_set_connection_value_n_nocheck_ (struct MHD_Connection *connection,
{
struct MHD_HTTP_Req_Header *pos;
- pos = connection_alloc_memory (connection,
- sizeof (struct MHD_HTTP_Res_Header));
+ pos = MHD_connection_alloc_memory_ (connection,
+ sizeof (struct MHD_HTTP_Res_Header));
if (NULL == pos)
return MHD_NO;
pos->header = key;
@@ -1033,8 +1033,8 @@ try_ready_normal_body (struct MHD_Connection *connection)
if (NULL != connection->resp_iov.iov)
return MHD_YES;
copy_size = response->data_iovcnt * sizeof(MHD_iovec_);
- connection->resp_iov.iov = connection_alloc_memory (connection,
- copy_size);
+ connection->resp_iov.iov = MHD_connection_alloc_memory_ (connection,
+ copy_size);
if (NULL == connection->resp_iov.iov)
{
MHD_mutex_unlock_chk_ (&response->mutex);
@@ -3103,8 +3103,8 @@ parse_cookie_header (struct MHD_Connection *connection)
if (0 == hdr_len)
return MHD_PARSE_COOKIE_OK;
- cpy = connection_alloc_memory (connection,
- hdr_len + 1);
+ cpy = MHD_connection_alloc_memory_ (connection,
+ hdr_len + 1);
if (NULL == cpy)
return MHD_PARSE_COOKIE_NO_MEMORY;
diff --git a/src/microhttpd/connection.h b/src/microhttpd/connection.h
@@ -190,4 +190,18 @@ MHD_connection_epoll_update_ (struct MHD_Connection *connection);
void
MHD_update_last_activity_ (struct MHD_Connection *connection);
+
+/**
+ * Allocate memory from connection's memory pool.
+ * If memory pool doesn't have enough free memory but read or write buffer
+ * have some unused memory, the size of the buffer will be reduced as needed.
+ * @param connection the connection to use
+ * @param size the size of allocated memory area
+ * @return pointer to allocated memory region in the pool or
+ * NULL if no memory is available
+ */
+void *
+MHD_connection_alloc_memory_ (struct MHD_Connection *connection,
+ size_t size);
+
#endif