libmicrohttpd2

HTTP server C library (MHD 2.x, alpha)
Log | Files | Refs | README | LICENSE

commit 4c39a988c3671e1a408958fa9ee07aa7b5c041db
parent b37d4d7d9fdb2dfdf3976377765a1de316a6d925
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date:   Tue,  9 Dec 2025 19:01:10 +0100

mhd_send: refactoring to use narrower type in internal functions

Diffstat:
Msrc/mhd2/mhd_send.c | 218++++++++++++++++++++++++++++++++++++++++++-------------------------------------
Msrc/mhd2/mhd_send.h | 30------------------------------
2 files changed, 116 insertions(+), 132 deletions(-)

diff --git a/src/mhd2/mhd_send.c b/src/mhd2/mhd_send.c @@ -57,7 +57,6 @@ #include <string.h> -#include "mhd_send.h" #include "sys_sockets_headers.h" #include "sys_ip_headers.h" #include "mhd_sockets_macros.h" @@ -93,6 +92,9 @@ # include "mhd_tls_funcs.h" #endif +#include "sckt_send.h" +#include "mhd_send.h" + #if defined(HAVE_SENDMSG) || defined(HAVE_WRITEV) || \ defined(MHD_SOCKETS_KIND_WINSOCK) # define mhd_USE_VECT_SEND 1 @@ -212,8 +214,17 @@ mhd_send_init_once (void) } -MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ bool -mhd_connection_set_nodelay_state (struct MHD_Connection *connection, +/** + * Set required TCP_NODELAY state for connection socket + * + * The function automatically updates sk.nodelay state. + * @param sk the socket data + * @param nodelay_state the requested new state of socket + * @return true if succeed, false if failed or not supported + * by the current platform / kernel. + */ +static MHD_FN_PAR_NONNULL_ALL_ bool +mhd_connection_set_nodelay_state (struct mhd_ConnSocket *restrict sk, bool nodelay_state) { #ifdef HAVE_DCLR_TCP_NODELAY @@ -221,26 +232,26 @@ mhd_connection_set_nodelay_state (struct MHD_Connection *connection, static const mhd_SCKT_OPT_BOOL on_val = 1; int err_code; - if (mhd_T_IS_YES (connection->sk.props.is_nonip)) + if (mhd_T_IS_YES (sk->props.is_nonip)) return false; - if (0 == mhd_setsockopt (connection->sk.fd, + if (0 == mhd_setsockopt (sk->fd, IPPROTO_TCP, TCP_NODELAY, (const void *) (nodelay_state ? &on_val : &off_val), sizeof (off_val))) { - connection->sk.state.nodelay = nodelay_state ? mhd_T_YES : mhd_T_NO; + sk->state.nodelay = nodelay_state ? mhd_T_YES : mhd_T_NO; return true; } err_code = mhd_SCKT_GET_LERR (); - if ((mhd_T_IS_NOT_YES (connection->sk.props.is_nonip)) && + if ((mhd_T_IS_NOT_YES (sk->props.is_nonip)) && (mhd_SCKT_ERR_IS_EINVAL (err_code) || mhd_SCKT_ERR_IS_NOPROTOOPT (err_code) || mhd_SCKT_ERR_IS_NOTSOCK (err_code))) { - connection->sk.props.is_nonip = mhd_T_YES; + sk->props.is_nonip = mhd_T_YES; } #if 0 /* No messages, avoid potential message flood in the log */ else @@ -251,14 +262,24 @@ mhd_connection_set_nodelay_state (struct MHD_Connection *connection, #endif /* No messages */ #else /* ! TCP_NODELAY */ (void) nodelay_state; /* Mute compiler warnings */ - connection->sk.state.nodelay = mhd_T_NO; + sk->state.nodelay = mhd_T_NO; #endif /* ! TCP_NODELAY */ return false; } -MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ bool -mhd_connection_set_cork_state (struct MHD_Connection *connection, +/** + * Set required cork state for connection socket + * + * The function automatically updates sk.corked state. + * + * @param sk the socket data + * @param cork_state the requested new state of socket + * @return true if succeed, false if failed or not supported + * by the current platform / kernel. + */ +static MHD_FN_PAR_NONNULL_ALL_ bool +mhd_connection_set_cork_state (struct mhd_ConnSocket *restrict sk, bool cork_state) { #if defined(mhd_TCP_CORK_NOPUSH) @@ -266,26 +287,26 @@ mhd_connection_set_cork_state (struct MHD_Connection *connection, static const mhd_SCKT_OPT_BOOL on_val = 1; int err_code; - if (mhd_T_IS_YES (connection->sk.props.is_nonip)) + if (mhd_T_IS_YES (sk->props.is_nonip)) return false; - if (0 == mhd_setsockopt (connection->sk.fd, + if (0 == mhd_setsockopt (sk->fd, IPPROTO_TCP, mhd_TCP_CORK_NOPUSH, (const void *) (cork_state ? &on_val : &off_val), sizeof (off_val))) { - connection->sk.state.corked = cork_state ? mhd_T_YES : mhd_T_NO; + sk->state.corked = cork_state ? mhd_T_YES : mhd_T_NO; return true; } err_code = mhd_SCKT_GET_LERR (); - if ((mhd_T_IS_NOT_YES (connection->sk.props.is_nonip)) && + if ((mhd_T_IS_NOT_YES (sk->props.is_nonip)) && (mhd_SCKT_ERR_IS_EINVAL (err_code) || mhd_SCKT_ERR_IS_NOPROTOOPT (err_code) || mhd_SCKT_ERR_IS_NOTSOCK (err_code))) { - connection->sk.props.is_nonip = mhd_T_YES; + sk->props.is_nonip = mhd_T_YES; } #if 0 /* No messages, avoid potential message flood in the log */ else @@ -302,7 +323,7 @@ mhd_connection_set_cork_state (struct MHD_Connection *connection, #else /* ! mhd_TCP_CORK_NOPUSH */ (void) cork_state; /* Mute compiler warnings. */ - connection->sk.state.corked = mhd_T_NO; + sk->state.corked = mhd_T_NO; #endif /* ! mhd_TCP_CORK_NOPUSH */ return false; } @@ -311,7 +332,7 @@ mhd_connection_set_cork_state (struct MHD_Connection *connection, /** * Handle pre-send setsockopt calls. * - * @param connection the MHD_Connection structure + * @param sk the socket data * @param plain_send set to true if plain send() or sendmsg() will be called, * set to false if TLS socket send(), sendfile() or * writev() will be called. @@ -319,7 +340,7 @@ mhd_connection_set_cork_state (struct MHD_Connection *connection, * the next call of send function. */ static void -pre_send_setopt (struct MHD_Connection *connection, +pre_send_setopt (struct mhd_ConnSocket *restrict sk, bool plain_send, bool push_data) { @@ -327,10 +348,10 @@ pre_send_setopt (struct MHD_Connection *connection, * Final piece is indicated by push_data == true. */ const bool buffer_data = (! push_data); - if (mhd_T_IS_YES (connection->sk.props.is_nonip)) + if (mhd_T_IS_YES (sk->props.is_nonip)) return; - // TODO: support inheriting of TCP_NODELAY and TCP_NOPUSH + // TODO: support inheriting of TCP_NODELAY and TCP_NOPUSH from accept() /* The goal is to minimise the total number of additional sys-calls * before and after send(). @@ -349,25 +370,25 @@ pre_send_setopt (struct MHD_Connection *connection, #endif /* ! mhd_USE_MSG_MORE */ #ifdef mhd_TCP_CORK_NOPUSH - if (mhd_T_IS_YES (connection->sk.state.corked)) + if (mhd_T_IS_YES (sk->state.corked)) return; /* The connection was already corked. */ /* Prefer 'cork' over 'no delay' as the 'cork' buffers better, regardless * of the number of received ACKs. */ - if (mhd_connection_set_cork_state (connection, true)) + if (mhd_connection_set_cork_state (sk, true)) return; /* The connection has been corked. */ /* Failed to cork the connection. * Really unlikely to happen on TCP connections. */ #endif /* mhd_TCP_CORK_NOPUSH */ - if (mhd_T_IS_NO (connection->sk.state.nodelay)) + if (mhd_T_IS_NO (sk->state.nodelay)) return; /* TCP_NODELAY was not set for the socket. * Nagle's algorithm will buffer some data. */ /* Try to reset TCP_NODELAY state for the socket. * Ignore possible error as no other options exist to * buffer data. */ - mhd_connection_set_nodelay_state (connection, false); + mhd_connection_set_nodelay_state (sk, false); /* TCP_NODELAY has been (hopefully) reset for the socket. * Nagle's algorithm will buffer some data. */ return; @@ -424,21 +445,21 @@ pre_send_setopt (struct MHD_Connection *connection, /* This is typical modern FreeBSD and OpenBSD behaviour. */ # endif /* ! mhd_NODELAY_SET_PUSH_DATA */ - if (mhd_T_IS_YES (connection->sk.state.corked)) + if (mhd_T_IS_YES (sk->state.corked)) return; /* Socket is corked. Data can be pushed by resetting of * TCP_CORK / TCP_NOPUSH after send() */ - else if (mhd_T_IS_NO (connection->sk.state.corked)) + else if (mhd_T_IS_NO (sk->state.corked)) { /* The socket is not corked. */ - if (mhd_T_IS_YES (connection->sk.state.nodelay)) + if (mhd_T_IS_YES (sk->state.nodelay)) return; /* TCP_NODELAY was already set, * data will be pushed automatically by the next send() */ # ifdef mhd_NODELAY_SET_PUSH_DATA - else if (mhd_T_IS_MAYBE (connection->sk.state.nodelay)) + else if (mhd_T_IS_MAYBE (sk->state.nodelay)) { /* Setting TCP_NODELAY may push data NOW. * Cork socket here and uncork after send(). */ - if (mhd_connection_set_cork_state (connection, true)) + if (mhd_connection_set_cork_state (sk, true)) return; /* The connection has been corked. * Data can be pushed by resetting of * TCP_CORK / TCP_NOPUSH after send() */ @@ -452,7 +473,7 @@ pre_send_setopt (struct MHD_Connection *connection, * to happen as this is only a backup solution when corking has failed. * Ignore possible error here as no other options exist to * push data. */ - mhd_connection_set_nodelay_state (connection, true); + mhd_connection_set_nodelay_state (sk, true); /* TCP_NODELAY has been (hopefully) set for the socket. * The data will be pushed by the next send(). */ return; @@ -471,7 +492,7 @@ pre_send_setopt (struct MHD_Connection *connection, /* Setting TCP_NODELAY is optimal here as data will be pushed * automatically by the next send() and no additional * sys-call are needed after the send(). */ - if (mhd_connection_set_nodelay_state (connection, true)) + if (mhd_connection_set_nodelay_state (sk, true)) return; else { @@ -481,7 +502,7 @@ pre_send_setopt (struct MHD_Connection *connection, * to uncork the socket after send(). This will push the data. */ /* Ignore possible error here as no other options exist to * push data. */ - mhd_connection_set_cork_state (connection, true); + mhd_connection_set_cork_state (sk, true); /* The connection has been (hopefully) corked. * Data can be pushed by resetting of TCP_CORK / TCP_NOPUSH * after send() */ @@ -491,13 +512,13 @@ pre_send_setopt (struct MHD_Connection *connection, } /* Corked state is unknown. Need to make a sys-call here otherwise * data may not be pushed. */ - if (mhd_connection_set_cork_state (connection, true)) + if (mhd_connection_set_cork_state (sk, true)) return; /* The connection has been corked. * Data can be pushed by resetting of * TCP_CORK / TCP_NOPUSH after send() */ /* The socket cannot be corked. * Really unlikely to happen on TCP connections */ - if (mhd_T_IS_YES (connection->sk.state.nodelay)) + if (mhd_T_IS_YES (sk->state.nodelay)) return; /* TCP_NODELAY was already set, * data will be pushed by the next send() */ @@ -509,7 +530,7 @@ pre_send_setopt (struct MHD_Connection *connection, # endif /* mhd_NODELAY_SET_PUSH_DATA */ /* Ignore possible error here as no other options exist to * push data. */ - mhd_connection_set_nodelay_state (connection, true); + mhd_connection_set_nodelay_state (sk, true); /* TCP_NODELAY has been (hopefully) set for the socket. * The data will be pushed by the next send(). */ return; @@ -526,12 +547,12 @@ pre_send_setopt (struct MHD_Connection *connection, /* This is old FreeBSD and Darwin behaviour. */ /* Uncork socket if socket wasn't uncorked. */ - if (mhd_T_IS_NOT_NO (connection->sk.state.corked)) - mhd_connection_set_cork_state (connection, false); + if (mhd_T_IS_NOT_NO (sk->state.corked)) + mhd_connection_set_cork_state (sk, false); /* Set TCP_NODELAY if it wasn't set. */ - if (mhd_T_IS_NOT_YES (connection->sk.state.nodelay)) - mhd_connection_set_nodelay_state (connection, true); + if (mhd_T_IS_NOT_YES (sk->state.nodelay)) + mhd_connection_set_nodelay_state (sk, true); return; # else /* mhd_NODELAY_SET_PUSH_DATA */ @@ -552,8 +573,8 @@ pre_send_setopt (struct MHD_Connection *connection, /* Buffering of data is controlled only by * Nagel's algorithm. */ /* Set TCP_NODELAY if it wasn't set. */ - if (mhd_T_IS_NOT_YES (connection->sk.state.nodelay)) - mhd_connection_set_nodelay_state (connection, true); + if (mhd_T_IS_NOT_YES (sk->state.nodelay)) + mhd_connection_set_nodelay_state (sk, true); #endif /* ! mhd_TCP_CORK_NOPUSH */ } @@ -571,15 +592,15 @@ pre_send_setopt (struct MHD_Connection *connection, * @return true if succeed, false if failed */ static bool -zero_send (struct MHD_Connection *connection) +zero_send (struct mhd_ConnSocket *restrict sk) { static const int dummy = 0; - if (mhd_T_IS_YES (connection->sk.props.is_nonip)) + if (mhd_T_IS_YES (sk->props.is_nonip)) return false; - mhd_assert (mhd_T_IS_NO (connection->sk.state.corked)); - mhd_assert (mhd_T_IS_YES (connection->sk.state.nodelay)); - if (0 == mhd_sys_send (connection->sk.fd, &dummy, 0)) + mhd_assert (mhd_T_IS_NO (sk->state.corked)); + mhd_assert (mhd_T_IS_YES (sk->state.nodelay)); + if (0 == mhd_sys_send (sk->fd, &dummy, 0)) return true; #if 0 /* No messages, avoid potential message flood in the log */ mhd_LOG_MSG (connection->daemon, MHD_SC_SOCKET_ZERO_SEND_FAILED, \ @@ -594,7 +615,7 @@ zero_send (struct MHD_Connection *connection) /** * Handle post-send setsockopt calls. * - * @param connection the MHD_Connection structure + * @param sk the socket data * @param plain_send_next set to true if plain send() or sendmsg() will be * called next, * set to false if TLS socket send(), sendfile() or @@ -602,7 +623,7 @@ zero_send (struct MHD_Connection *connection) * @param push_data whether to push data to the network from buffers */ static void -post_send_setopt (struct MHD_Connection *connection, +post_send_setopt (struct mhd_ConnSocket *restrict sk, bool plain_send_next, bool push_data) { @@ -610,7 +631,7 @@ post_send_setopt (struct MHD_Connection *connection, * Final piece is indicated by push_data == true. */ const bool buffer_data = (! push_data); - if (mhd_T_IS_YES (connection->sk.props.is_nonip)) + if (mhd_T_IS_YES (sk->props.is_nonip)) return; if (buffer_data) return; /* Nothing to do after the send(). */ @@ -621,8 +642,8 @@ post_send_setopt (struct MHD_Connection *connection, /* Need to push data. */ #ifdef mhd_TCP_CORK_NOPUSH - if (mhd_T_IS_YES (connection->sk.state.nodelay) && \ - mhd_T_IS_NO (connection->sk.state.corked)) + if (mhd_T_IS_YES (sk->state.nodelay) && \ + mhd_T_IS_NO (sk->state.corked)) return; /* Data has been already pushed by last send(). */ # ifdef mhd_CORK_RESET_PUSH_DATA_ALWAYS @@ -649,14 +670,14 @@ post_send_setopt (struct MHD_Connection *connection, * resetting of TCP_CORK so next final send without MSG_MORE will push * data to the network (without additional sys-call to push data). */ - if (mhd_T_IS_NOT_YES (connection->sk.state.nodelay) || + if (mhd_T_IS_NOT_YES (sk->state.nodelay) || (! plain_send_next)) { - if (mhd_connection_set_nodelay_state (connection, true)) + if (mhd_connection_set_nodelay_state (sk, true)) return; /* Data has been pushed by TCP_NODELAY. */ /* Failed to set TCP_NODELAY for the socket. * Really unlikely to happen on TCP connections. */ - if (mhd_connection_set_cork_state (connection, false)) + if (mhd_connection_set_cork_state (sk, false)) return; /* Data has been pushed by uncorking the socket. */ /* Failed to uncork the socket. * Really unlikely to happen on TCP connections. */ @@ -665,11 +686,11 @@ post_send_setopt (struct MHD_Connection *connection, } else { - if (mhd_connection_set_cork_state (connection, false)) + if (mhd_connection_set_cork_state (sk, false)) return; /* Data has been pushed by uncorking the socket. */ /* Failed to uncork the socket. * Really unlikely to happen on TCP connections. */ - if (mhd_connection_set_nodelay_state (connection, true)) + if (mhd_connection_set_nodelay_state (sk, true)) return; /* Data has been pushed by TCP_NODELAY. */ /* Failed to set TCP_NODELAY for the socket. * Really unlikely to happen on TCP connections. */ @@ -679,11 +700,11 @@ post_send_setopt (struct MHD_Connection *connection, # else /* ! mhd_USE_MSG_MORE */ /* Push data by setting TCP_NODELAY here as uncorking here * would require corking the socket before sending the next response. */ - if (mhd_connection_set_nodelay_state (connection, true)) + if (mhd_connection_set_nodelay_state (sk, true)) return; /* Data was pushed by TCP_NODELAY. */ /* Failed to set TCP_NODELAY for the socket. * Really unlikely to happen on TCP connections. */ - if (mhd_connection_set_cork_state (connection, false)) + if (mhd_connection_set_cork_state (sk, false)) return; /* Data was pushed by uncorking the socket. */ /* Failed to uncork the socket. * Really unlikely to happen on TCP connections. */ @@ -691,7 +712,7 @@ post_send_setopt (struct MHD_Connection *connection, /* The socket remains corked, no way to push data */ # endif /* ! mhd_USE_MSG_MORE */ # else /* ! mhd_NODELAY_SET_PUSH_DATA_ALWAYS */ - if (mhd_connection_set_cork_state (connection, false)) + if (mhd_connection_set_cork_state (sk, false)) return; /* Data was pushed by uncorking the socket. */ /* Failed to uncork the socket. * Really unlikely to happen on TCP connections. */ @@ -701,17 +722,17 @@ post_send_setopt (struct MHD_Connection *connection, # else /* ! mhd_CORK_RESET_PUSH_DATA_ALWAYS */ /* This is old FreeBSD or Darwin kernel. */ - if (mhd_T_IS_NO (connection->sk.state.corked)) + if (mhd_T_IS_NO (sk->state.corked)) { - mhd_assert (mhd_T_IS_NOT_YES (connection->sk.state.nodelay)); + mhd_assert (mhd_T_IS_NOT_YES (sk->state.nodelay)); /* Unlikely to reach this code. * TCP_NODELAY should be turned on before send(). */ - if (mhd_connection_set_nodelay_state (connection, true)) + if (mhd_connection_set_nodelay_state (sk, true)) { /* TCP_NODELAY has been set on uncorked socket. * Use zero-send to push the data. */ - if (zero_send (connection)) + if (zero_send (sk)) return; /* The data has been pushed by zero-send. */ } @@ -721,11 +742,11 @@ post_send_setopt (struct MHD_Connection *connection, else { #ifdef mhd_CORK_RESET_PUSH_DATA - enum mhd_Tristate old_cork_state = connection->sk.state.corked; + enum mhd_Tristate old_cork_state = sk->state.corked; #endif /* mhd_CORK_RESET_PUSH_DATA */ /* The socket is corked or cork state is unknown. */ - if (mhd_connection_set_cork_state (connection, false)) + if (mhd_connection_set_cork_state (sk, false)) { #ifdef mhd_CORK_RESET_PUSH_DATA /* Modern FreeBSD or OpenBSD kernel */ @@ -736,12 +757,12 @@ post_send_setopt (struct MHD_Connection *connection, /* Unlikely to reach this code. * The data should be pushed by uncorking (FreeBSD) or * the socket should be uncorked before send(). */ - if (mhd_T_IS_YES (connection->sk.state.nodelay) || - (mhd_connection_set_nodelay_state (connection, true))) + if (mhd_T_IS_YES (sk->state.nodelay) || + (mhd_connection_set_nodelay_state (sk, true))) { /* TCP_NODELAY is turned ON on uncorked socket. * Use zero-send to push the data. */ - if (zero_send (connection)) + if (zero_send (sk)) return; /* The data has been pushed by zero-send. */ } } @@ -751,17 +772,17 @@ post_send_setopt (struct MHD_Connection *connection, #else /* ! mhd_TCP_CORK_NOPUSH */ /* Corking is not supported. Buffering is controlled * by TCP_NODELAY only. */ - mhd_assert (mhd_T_IS_NOT_YES (connection->sk.state.corked)); - if (mhd_T_IS_YES (connection->sk.state.nodelay)) + mhd_assert (mhd_T_IS_NOT_YES (sk->state.corked)); + if (mhd_T_IS_YES (sk->state.nodelay)) return; /* Data was already pushed by send(). */ /* Unlikely to reach this code. * TCP_NODELAY should be turned on before send(). */ - if (mhd_connection_set_nodelay_state (connection, true)) + if (mhd_connection_set_nodelay_state (sk, true)) { /* TCP_NODELAY has been set. * Use zero-send to try to push the data. */ - if (zero_send (connection)) + if (zero_send (sk)) return; /* The data has been pushed by zero-send. */ } @@ -782,7 +803,7 @@ post_send_setopt (struct MHD_Connection *connection, static MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (3,2) MHD_FN_PAR_OUT_ (5) enum mhd_SocketError -mhd_send_plain (struct MHD_Connection *restrict c, +mhd_send_plain (struct mhd_ConnSocket *restrict sk, size_t buf_size, const char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)], bool push_data, @@ -792,23 +813,20 @@ mhd_send_plain (struct MHD_Connection *restrict c, ssize_t res; bool full_buf_sent; - mhd_assert (! mhd_C_HAS_TLS (c)); - mhd_assert (! mhd_D_HAS_TLS (c->daemon)); - if (buf_size > MHD_SCKT_SEND_MAX_SIZE_) { buf_size = MHD_SCKT_SEND_MAX_SIZE_; /* send() return value limit */ push_data = false; /* Incomplete send */ } - pre_send_setopt (c, true, push_data); + pre_send_setopt (sk, true, push_data); #ifdef mhd_USE_MSG_MORE - res = mhd_sys_send4 (c->sk.fd, + res = mhd_sys_send4 (sk->fd, buf, buf_size, push_data ? 0 : MSG_MORE); #else - res = mhd_sys_send4 (c->sk.fd, + res = mhd_sys_send4 (sk->fd, buf, buf_size, 0); @@ -821,10 +839,8 @@ mhd_send_plain (struct MHD_Connection *restrict c, err = mhd_socket_error_get_from_sys_err (mhd_SCKT_GET_LERR ()); if (mhd_SOCKET_ERR_AGAIN == err) - c->sk.ready = (enum mhd_SocketNetState) /* Clear 'send-ready' */ - (((unsigned int) c->sk.ready) - & (~(enum mhd_SocketNetState) - mhd_SOCKET_NET_STATE_SEND_READY)); + mhd_SCKT_NET_ST_CLEAR_FLAG (&(sk->ready), + mhd_SOCKET_NET_STATE_SEND_READY); return err; } @@ -832,11 +848,9 @@ mhd_send_plain (struct MHD_Connection *restrict c, full_buf_sent = (buf_size == (size_t) res); - if (! full_buf_sent || ! c->sk.props.is_nonblck) - c->sk.ready = (enum mhd_SocketNetState) /* Clear 'send-ready' */ - (((unsigned int) c->sk.ready) - & (~(enum mhd_SocketNetState) - mhd_SOCKET_NET_STATE_SEND_READY)); + if (! full_buf_sent || ! sk->props.is_nonblck) + mhd_SCKT_NET_ST_CLEAR_FLAG (&(sk->ready), + mhd_SOCKET_NET_STATE_SEND_READY); /* If there is a need to push the data from network buffers * call post_send_setopt(). */ @@ -844,7 +858,7 @@ mhd_send_plain (struct MHD_Connection *restrict c, * MSG_MORE support) will be used for the next reply so assume * that next sending will be the same, like this call. */ if (push_data && full_buf_sent) - post_send_setopt (c, true, push_data); + post_send_setopt (sk, true, push_data); return mhd_SOCKET_ERR_NO_ERROR; } @@ -868,7 +882,7 @@ mhd_send_tls (struct MHD_Connection *restrict c, mhd_assert (mhd_D_HAS_TLS (c->daemon)); mhd_assert (0 != buf_size); - pre_send_setopt (c, false, push_data); + pre_send_setopt (&(c->sk), false, push_data); res = mhd_tls_conn_send (c->tls, buf_size, @@ -894,7 +908,7 @@ mhd_send_tls (struct MHD_Connection *restrict c, /* If there is a need to push the data from network buffers * call post_send_setopt(). */ if (push_data && (buf_size == *sent)) - post_send_setopt (c, false, true); + post_send_setopt (&(c->sk), false, true); return mhd_SOCKET_ERR_NO_ERROR; } @@ -923,7 +937,7 @@ mhd_send_data (struct MHD_Connection *restrict connection, sent); #endif /* MHD_SUPPORT_HTTPS */ - return mhd_send_plain (connection, + return mhd_send_plain (&(connection->sk), buf_size, buf, push_data, @@ -1069,7 +1083,7 @@ mhd_send_hdr_and_body (struct MHD_Connection *restrict connection, push_body = complete_response; } - pre_send_setopt (connection, + pre_send_setopt (&(connection->sk), #ifdef HAVE_SENDMSG true, #else /* ! HAVE_SENDMSG */ @@ -1158,7 +1172,7 @@ mhd_send_hdr_and_body (struct MHD_Connection *restrict connection, * it's unknown whether next 'send' will be plain send() / sendmsg() or * sendfile() will be used so assume that next final send() will be * the same, like for this response. */ - post_send_setopt (connection, + post_send_setopt (&(connection->sk), #ifdef HAVE_SENDMSG true, /* Assume the same type of the send function */ #else /* ! HAVE_SENDMSG */ @@ -1172,7 +1186,7 @@ mhd_send_hdr_and_body (struct MHD_Connection *restrict connection, /* The header has been sent completely and there is a * need to push the header data. */ /* Luckily the type of send function will be used next is known. */ - post_send_setopt (connection, + post_send_setopt (&(connection->sk), true, true); } @@ -1249,7 +1263,7 @@ mhd_send_sendfile (struct MHD_Connection *restrict c, } mhd_assert (0 != send_size); - pre_send_setopt (c, false, push_data); + pre_send_setopt (&(c->sk), false, push_data); sent_bytes = 0; ret = mhd_SOCKET_ERR_NO_ERROR; @@ -1406,7 +1420,7 @@ mhd_send_sendfile (struct MHD_Connection *restrict c, * response so assume that next response will be the same. */ if ((push_data) && (send_size == sent_bytes)) - post_send_setopt (c, true, push_data); + post_send_setopt (&(c->sk), true, push_data); *sent = sent_bytes; return ret; @@ -1480,7 +1494,7 @@ send_iov_nontls (struct MHD_Connection *restrict connection, msg.msg_controllen = 0; msg.msg_flags = 0; - pre_send_setopt (connection, true, push_data); + pre_send_setopt (&(connection->sk), true, push_data); res = sendmsg (connection->sk.fd, &msg, mhd_MSG_NOSIGNAL # ifdef mhd_USE_MSG_MORE @@ -1492,7 +1506,7 @@ send_iov_nontls (struct MHD_Connection *restrict connection, else send_error = true; #elif defined(HAVE_WRITEV) - pre_send_setopt (connection, false, push_data); + pre_send_setopt (&(connection->sk), false, push_data); res = writev (connection->sk.fd, r_iov->iov + r_iov->sent, items_to_send); if (0 < res) @@ -1511,7 +1525,7 @@ send_iov_nontls (struct MHD_Connection *restrict connection, #else /* ! _WIN64 */ cnt_w = (DWORD) items_to_send; #endif /* ! _WIN64 */ - pre_send_setopt (connection, true, push_data); + pre_send_setopt (&(connection->sk), true, push_data); if (0 == WSASend (connection->sk.fd, (LPWSABUF) (r_iov->iov + r_iov->sent), cnt_w, @@ -1559,7 +1573,7 @@ send_iov_nontls (struct MHD_Connection *restrict connection, } if (r_iov->cnt == r_iov->sent) - post_send_setopt (connection, true, push_data); + post_send_setopt (&(connection->sk), true, push_data); else { connection->sk.ready = (enum mhd_SocketNetState) /* Clear 'send-ready' */ diff --git a/src/mhd2/mhd_send.h b/src/mhd2/mhd_send.h @@ -159,35 +159,5 @@ mhd_send_iovec (struct MHD_Connection *restrict connection, size_t *restrict sent) MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_ (4); -/** - * Set required TCP_NODELAY state for connection socket - * - * The function automatically updates sk.nodelay state. - * @param connection the connection to manipulate - * @param nodelay_state the requested new state of socket - * @return true if succeed, false if failed or not supported - * by the current platform / kernel. - */ -MHD_INTERNAL bool -mhd_connection_set_nodelay_state (struct MHD_Connection *connection, - bool nodelay_state) -MHD_FN_PAR_NONNULL_ALL_; - - -/** - * Set required cork state for connection socket - * - * The function automatically updates sk.corked state. - * - * @param connection the connection to manipulate - * @param cork_state the requested new state of socket - * @return true if succeed, false if failed or not supported - * by the current platform / kernel. - */ -MHD_INTERNAL bool -mhd_connection_set_cork_state (struct MHD_Connection *connection, - bool cork_state) -MHD_FN_PAR_NONNULL_ALL_; - #endif /* MHD_SEND_H */