libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 2e996ee5c2cbf9cb36b12c1152d81b1477607b2c
parent 127a964c7bab61a58fb4b1dc3b112eb784820181
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Wed, 14 Jun 2023 10:49:10 +0300

Added proper connection's buffers pre-initialisaion

Diffstat:
Msrc/microhttpd/connection.c | 41+++++++++++++++++++++++++++++++++++++++++
Msrc/microhttpd/connection.h | 8++++++++
Msrc/microhttpd/daemon.c | 3+++
3 files changed, 52 insertions(+), 0 deletions(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c @@ -6069,6 +6069,47 @@ cleanup_connection (struct MHD_Connection *connection) /** + * Set initial internal states for the connection to start reading and + * processing incoming data. + * @param c the connection to process + */ +void +MHD_connection_set_initial_state_ (struct MHD_Connection *c) +{ + size_t read_buf_size; + +#ifdef HTTPS_SUPPORT + mhd_assert ( (0 == (c->daemon->options & MHD_USE_TLS)) || \ + (MHD_TLS_CONN_INIT == c->tls_state) ); + mhd_assert ( (0 != (c->daemon->options & MHD_USE_TLS)) || \ + (MHD_TLS_CONN_NO_TLS == c->tls_state) ); +#endif /* HTTPS_SUPPORT */ + mhd_assert (MHD_CONNECTION_INIT == c->state); + + c->keepalive = MHD_CONN_KEEPALIVE_UNKOWN; + c->event_loop_info = MHD_EVENT_LOOP_INFO_READ; + + memset (&c->rq, 0, sizeof(c->rq)); + memset (&c->rp, 0, sizeof(c->rp)); + + c->write_buffer = NULL; + c->write_buffer_size = 0; + c->write_buffer_send_offset = 0; + c->write_buffer_append_offset = 0; + + c->continue_message_write_offset = 0; + + c->read_buffer_offset = 0; + read_buf_size = c->daemon->pool_size / 2; + c->read_buffer + = MHD_pool_allocate (c->pool, + read_buf_size, + false); + c->read_buffer_size = read_buf_size; +} + + +/** * Reset connection after request-reply cycle. * @param connection the connection to process * @param reuse the flag to choose whether to close connection or diff --git a/src/microhttpd/connection.h b/src/microhttpd/connection.h @@ -87,6 +87,14 @@ MHD_set_http_callbacks_ (struct MHD_Connection *connection); /** + * Set initial internal states for the connection to start reading and + * processing incoming data. + * @param c the connection to process + */ +void +MHD_connection_set_initial_state_ (struct MHD_Connection *c); + +/** * This function handles a particular connection when it has been * determined that there is data to be read off a socket. All * implementations (multithreaded, external polling, internal polling) diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c @@ -2801,6 +2801,9 @@ new_connection_process_ (struct MHD_Daemon *daemon, connection); } MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); + + MHD_connection_set_initial_state_ (connection); + if (NULL != daemon->notify_connection) daemon->notify_connection (daemon->notify_connection_cls, connection,