[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libmicrohttpd] 02/02: Added: track TCP_NODELAY state of client sockets
From: |
gnunet |
Subject: |
[libmicrohttpd] 02/02: Added: track TCP_NODELAY state of client sockets |
Date: |
Tue, 01 Dec 2020 19:24:40 +0100 |
This is an automated email from the git hooks/post-receive script.
karlson2k pushed a commit to branch master
in repository libmicrohttpd.
commit 0e0ad2b23834a348a7b04289579ff7cbdd9c8a61
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Tue Dec 1 21:22:02 2020 +0300
Added: track TCP_NODELAY state of client sockets
---
src/microhttpd/daemon.c | 28 ++++++++++++++++++++--------
src/microhttpd/internal.h | 16 ++++++++++++++++
src/microhttpd/mhd_send.c | 9 ++++++---
3 files changed, 42 insertions(+), 11 deletions(-)
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 2f0a2dcc..797c5d49 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -2357,6 +2357,7 @@ psk_gnutls_adapter (gnutls_session_t session,
* to receive an HTTP request from this socket next).
* @param addr IP address of the client
* @param addrlen number of bytes in @a addr
+ * @param external_add indicate that socket has been added externally
* @param non_blck indicate that socket in non-blocking mode
* @param pconnection pointer to variable that receive pointer to
* the new connection structure.
@@ -2370,6 +2371,7 @@ new_connection_prepare_ (struct MHD_Daemon *daemon,
MHD_socket client_socket,
const struct sockaddr *addr,
socklen_t addrlen,
+ bool external_add,
bool non_blck,
struct MHD_Connection **pconnection)
{
@@ -2460,19 +2462,29 @@ new_connection_prepare_ (struct MHD_Daemon *daemon,
}
connection->sk_cork_on = false;
#if defined(MHD_TCP_CORK_NOPUSH) || defined(MHD_USE_MSG_MORE)
+ (void) external_add; /* Mute compiler warning */
/* 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)) &&
- (EOPNOTSUPP != errno) )
+ if (0 != MHD_socket_set_nodelay_ (client_socket, true))
{
+ if (EOPNOTSUPP != MHD_socket_get_error_ ())
+ {
#ifdef HAVE_MESSAGES
- MHD_DLOG (daemon,
- _ ("Failed to disable TCP Nagle on socket: %s\n"),
- MHD_socket_last_strerr_ ());
+ MHD_DLOG (daemon,
+ _ ("Failed to disable TCP Nagle on socket: %s\n"),
+ MHD_socket_last_strerr_ ());
#endif
+ }
+ connection->sk_nodelay = _MHD_UNKNOWN;
}
-#endif
+ else
+ connection->sk_nodelay = _MHD_ON;
+#else /* !MHD_TCP_CORK_NOPUSH && !MHD_USE_MSG_MORE */
+ if (! external_add)
+ connection->sk_nodelay = _MHD_OFF;
+ else
+ connection->sk_nodelay = _MHD_UNKNOWN;
+#endif /* !MHD_TCP_CORK_NOPUSH && !MHD_USE_MSG_MORE */
connection->connection_timeout = daemon->connection_timeout;
if (NULL == (connection->addr = malloc (addrlen)))
@@ -2911,7 +2923,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
}
if (MHD_NO == new_connection_prepare_ (daemon, client_socket, addr, addrlen,
- non_blck, &connection))
+ external_add, non_blck, &connection))
return MHD_NO;
if ((external_add) &&
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index 8ecd4ed6..fd5b1748 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -166,6 +166,17 @@ extern void *mhd_panic_cls;
#endif /* ! MHD_STATICSTR_LEN_ */
+/**
+ * Tri-state on/off/unknown
+ */
+enum MHD_tristate
+{
+ _MHD_UNKNOWN = -1, /**< State is not yet checked nor set */
+ _MHD_OFF = false, /**< State is "off" / "disabled" */
+ _MHD_ON = true /**< State is "on" / "enabled" */
+};
+
+
/**
* State of the socket with respect to epoll (bitmask).
*/
@@ -923,6 +934,11 @@ struct MHD_Connection
*/
bool sk_cork_on;
+ /**
+ * Tracks TCP_NODELAY state of the connection socket.
+ */
+ enum MHD_tristate sk_nodelay;
+
/**
* Has this socket been closed for reading (i.e. other side closed
* the connection)? If so, we must completely close the connection
diff --git a/src/microhttpd/mhd_send.c b/src/microhttpd/mhd_send.c
index 4c937078..0cdd1265 100644
--- a/src/microhttpd/mhd_send.c
+++ b/src/microhttpd/mhd_send.c
@@ -194,14 +194,17 @@ pre_send_setopt (struct MHD_Connection *connection,
/* CORK/NOPUSH do not exist on this platform,
Turning on/off of Naggle's algorithm
(otherwise we keep it always off) */
- if (connection->sk_cork_on == buffer_data)
+ if (connection->sk_nodelay == push_data)
{
/* nothing to do, success! */
return;
}
if (0 == MHD_socket_set_nodelay_ (connection->socket_fd,
(push_data)))
- connection->sk_cork_on = !push_data;
+ {
+ connection->sk_cork_on = ! push_data;
+ connection->sk_nodelay = push_data;
+ }
#endif
}
@@ -430,7 +433,7 @@ MHD_send_on_connection_ (struct MHD_Connection *connection,
#endif /* EPOLL_SUPPORT */
}
post_send_setopt (connection, tls_conn,
- (push_data && (buffer_size == (size_t) ret)) );
+ (push_data && (buffer_size == (size_t) ret)) );
return ret;
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.