libmicrohttpd

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

commit b9e0a0ac45e195288dc1da99a8a68574d6255c03
parent 0e0ad2b23834a348a7b04289579ff7cbdd9c8a61
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Thu,  3 Dec 2020 19:51:02 +0300

Stopped using sk_cork_on for TCP_NODELAY tracking.

Replaced sk_cork_on with tri-state sk_corked.
TCP_NODELAY is tracked on separate member.

Diffstat:
Msrc/microhttpd/connection.c | 8+++-----
Msrc/microhttpd/daemon.c | 7+++++--
Msrc/microhttpd/internal.h | 5++---
Msrc/microhttpd/mhd_send.c | 29++++++++++-------------------
Msrc/microhttpd/response.c | 8++++----
5 files changed, 24 insertions(+), 33 deletions(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c @@ -2408,11 +2408,9 @@ check_write_done (struct MHD_Connection *connection, enum MHD_CONNECTION_STATE next_state) { if ( (connection->write_buffer_append_offset != - connection->write_buffer_send_offset) || - /* if we expected to turn cork off, and it is still on, - we are not finished sending (can happen with gnutls_record_uncork) */ - ( (connection->sk_cork_on) && - (MHD_CONNECTION_HEADERS_SENDING != connection->state) ) ) + connection->write_buffer_send_offset) + /* || data_in_tls_buffers == true */ + ) return MHD_NO; connection->write_buffer_append_offset = 0; connection->write_buffer_send_offset = 0; diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c @@ -2460,9 +2460,12 @@ new_connection_prepare_ (struct MHD_Daemon *daemon, errno = eno; return MHD_NO; } - connection->sk_cork_on = false; #if defined(MHD_TCP_CORK_NOPUSH) || defined(MHD_USE_MSG_MORE) - (void) external_add; /* Mute compiler warning */ + if (! external_add) + connection->sk_corked = _MHD_OFF; + else + connection->sk_corked = _MHD_UNKNOWN; + /* We will use TCP_CORK or TCP_NOPUSH or MSG_MORE to control transmission, disable Nagle's algorithm (always) */ if (0 != MHD_socket_set_nodelay_ (client_socket, true)) diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h @@ -929,10 +929,9 @@ struct MHD_Connection bool sk_nonblck; /** - * Indicate whether connection socket has TCP_CORK / Nagle’s algorithm turned on/off - * on this socket. + * Tracks TCP_CORK / TCP_NOPUSH of the connection socket. */ - bool sk_cork_on; + enum MHD_tristate sk_corked; /** * Tracks TCP_NODELAY state of the connection socket. diff --git a/src/microhttpd/mhd_send.c b/src/microhttpd/mhd_send.c @@ -137,19 +137,16 @@ pre_send_setopt (struct MHD_Connection *connection, #endif /* ! MHD_USE_MSG_MORE */ #if defined(MHD_TCP_CORK_NOPUSH) - /* If sk_cork_on is already what we pass in, return. */ - if (connection->sk_cork_on == buffer_data) - { - /* nothing to do, success! */ + /* If connection is already in required corked state, do nothing. */ + if (connection->sk_corked == buffer_data) return; - } if (push_data) - return; /* nothing to do *pre* syscall! */ + return; /* nothing to do *pre* syscall! BUG: to be fixed */ ret = MHD_socket_cork_ (connection->socket_fd, - true); + buffer_data); if (0 != ret) { - connection->sk_cork_on = true; + connection->sk_corked = buffer_data; return; } switch (errno) @@ -201,10 +198,7 @@ pre_send_setopt (struct MHD_Connection *connection, } if (0 == MHD_socket_set_nodelay_ (connection->socket_fd, (push_data))) - { - connection->sk_cork_on = ! push_data; connection->sk_nodelay = push_data; - } #endif } @@ -240,21 +234,18 @@ post_send_setopt (struct MHD_Connection *connection, #endif /* ! MHD_USE_MSG_MORE */ #if defined(MHD_TCP_CORK_NOPUSH) - /* If sk_cork_on is already what we pass in, return. */ - if (connection->sk_cork_on == buffer_data) - { - /* nothing to do, success! */ + /* If connection is already in required corked state, do nothing. */ + if (connection->sk_corked == buffer_data) return; - } if (buffer_data) return; /* nothing to do *post* syscall (in fact, we should never - get here, as sk_cork_on should have succeeded in the + get here, as sk_corked should have succeeded in the pre-syscall) */ ret = MHD_socket_cork_ (connection->socket_fd, - false); + buffer_data); if (0 != ret) { - connection->sk_cork_on = false; + connection->sk_corked = buffer_data; return; } switch (errno) diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c @@ -892,24 +892,24 @@ MHD_upgrade_action (struct MHD_UpgradeResponseHandle *urh, MHD_resume_connection (connection); return MHD_YES; case MHD_UPGRADE_ACTION_CORK_ON: - if (connection->sk_cork_on) + if (_MHD_ON == connection->sk_corked) return MHD_YES; if (0 != MHD_socket_cork_ (connection->socket_fd, true)) { - connection->sk_cork_on = true; + connection->sk_corked = _MHD_ON; return MHD_YES; } return MHD_NO; case MHD_UPGRADE_ACTION_CORK_OFF: - if (! connection->sk_cork_on) + if (_MHD_OFF == connection->sk_corked) return MHD_YES; if (0 != MHD_socket_cork_ (connection->socket_fd, false)) { - connection->sk_cork_on = false; + connection->sk_corked = _MHD_OFF; return MHD_YES; } return MHD_NO;