gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libmicrohttpd] branch master updated (331bc629 -> 0e0ad2b2)


From: gnunet
Subject: [libmicrohttpd] branch master updated (331bc629 -> 0e0ad2b2)
Date: Tue, 01 Dec 2020 19:24:38 +0100

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from 331bc629 mhd_send: renamed functions and parameters to reflect the key 
purpose.
     new 5df71088 daemon.c: fixed: set TCP_NODELAY for externally added 
connections as well if platform suppots TCP_CORK or TCP_NOPUSH
     new 0e0ad2b2 Added: track TCP_NODELAY state of client sockets

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/microhttpd/daemon.c   | 42 +++++++++++++++++++++++++++---------------
 src/microhttpd/internal.h | 16 ++++++++++++++++
 src/microhttpd/mhd_send.c |  9 ++++++---
 3 files changed, 49 insertions(+), 18 deletions(-)

diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 62e981e6..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)
 {
@@ -2459,6 +2461,30 @@ new_connection_prepare_ (struct MHD_Daemon *daemon,
     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 */
+  /* 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))
+  {
+    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_ ());
+#endif
+    }
+    connection->sk_nodelay = _MHD_UNKNOWN;
+  }
+  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)))
@@ -2897,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) &&
@@ -3507,20 +3533,6 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
     }
     return MHD_NO;
   }
-#if defined(MHD_TCP_CORK_NOPUSH) || defined(MHD_USE_MSG_MORE)
-  /* 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_ (s,
-                                      true)) &&
-       (EOPNOTSUPP != errno) )
-  {
-#ifdef HAVE_MESSAGES
-    MHD_DLOG (daemon,
-              _ ("Failed to disable TCP Nagle on socket: %s\n"),
-              MHD_socket_last_strerr_ ());
-#endif
-  }
-#endif
 #if ! defined(USE_ACCEPT4) || ! defined(HAVE_SOCK_NONBLOCK)
   if (! MHD_socket_nonblocking_ (s))
   {
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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]