gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [libmicrohttpd] 68/154: Add MHD_send_socket_state_cork_node


From: gnunet
Subject: [GNUnet-SVN] [libmicrohttpd] 68/154: Add MHD_send_socket_state_cork_nodelay_ and use it.
Date: Mon, 19 Aug 2019 10:16:20 +0200

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

ng0 pushed a commit to branch master
in repository libmicrohttpd.

commit 9a088e236f55f076d2500f023949bff74f72e930
Author: ng0 <address@hidden>
AuthorDate: Wed Jul 24 12:22:04 2019 +0000

    Add MHD_send_socket_state_cork_nodelay_ and use it.
---
 src/microhttpd/mhd_send.c | 82 +++++++++++++++++++++++++++++------------------
 src/microhttpd/mhd_send.h |  7 ++++
 2 files changed, 57 insertions(+), 32 deletions(-)

diff --git a/src/microhttpd/mhd_send.c b/src/microhttpd/mhd_send.c
index 56461942..b235c6ff 100644
--- a/src/microhttpd/mhd_send.c
+++ b/src/microhttpd/mhd_send.c
@@ -63,6 +63,46 @@ MHD_send_socket_state_nodelay_ (struct MHD_Connection 
*connection,
 #endif
 }
 
+/**
+ * Set TCP_NODELAY flag on socket and save the
+ * #sk_tcp_nodelay_on state.
+ *
+ * @param connection the MHD_Connection structure
+ * @param cork_value the state to set, boolean
+ * @param cork_state the boolean value passed to #sk_tcp_nodelay_on
+ * @param nodelay_value the state to set, boolean
+ * @param nodelay_state the boolean value passed to #sk_tcp_nodelay_on
+ */
+void
+MHD_send_socket_state_cork_nodelay_ (struct MHD_Connection *connection,
+                                     bool cork_value,
+                                     bool cork_state,
+                                     bool nodelay_value,
+                                     bool nodelay_state)
+{
+#if TCP_CORK && TCP_NODELAY
+  const MHD_SCKT_OPT_BOOL_ cork_state_val = cork_value ? 1 : 0;
+  const MHD_SCKT_OPT_BOOL_ nodelay_state_val = nodelay_value ? 1 : 0;
+
+  if (0 == setsockopt (connection->socket_fd,
+                       IPPROTO_TCP,
+                       TCP_CORK,
+                       (const void *) &cork_state_val,
+                       sizeof (cork_state_val)))
+    {
+      connection->sk_tcp_nodelay_on = cork_state;
+    }
+  else if (0 == setsockopt (connection->socket_fd,
+                            IPPROTO_TCP,
+                            TCP_NODELAY,
+                            (const void *) &nodelay_state_val,
+                            sizeof (nodelay_state_val)))
+    {
+      connection->sk_tcp_nodelay_on = nodelay_state;
+    }
+#endif
+}
+
 /**
  * Set TCP_NOPUSH flag on socket and save the
  * #sk_tcp_nodelay_on state.
@@ -183,22 +223,11 @@ MHD_send_on_connection_ (struct MHD_Connection 
*connection,
    * No other system in 2019-06 has TCP_CORK. */
   if ((! using_tls) && (use_corknopush) && (have_cork && ! want_cork))
     {
-      if (0 == setsockopt (s,
-                           IPPROTO_TCP,
-                           TCP_CORK,
-                           (const void *) &off_val,
-                           sizeof (off_val)))
-      {
-        connection->sk_tcp_nodelay_on = true;
-      }
-      else if (0 == setsockopt (s,
-                                IPPROTO_TCP,
-                                TCP_NODELAY,
-                                (const void *) &on_val,
-                                sizeof (on_val)))
-      {
-        connection->sk_tcp_nodelay_on = true;
-      }
+      MHD_send_socket_state_cork_nodelay_ (connection,
+                                           false,
+                                           true,
+                                           true,
+                                           true);
     }
 #elif TCP_NOPUSH
   /* TCP_NOPUSH on FreeBSD is equal to cork on Linux, with the
@@ -297,22 +326,11 @@ MHD_send_on_connection_ (struct MHD_Connection 
*connection,
 #if TCP_CORK
   if ((! using_tls) && (use_corknopush) && (! have_cork && want_cork && ! 
have_more))
     {
-      if (0 == setsockopt (s,
-                           IPPROTO_TCP,
-                           TCP_CORK,
-                           (const void *) &on_val,
-                           sizeof (on_val)))
-      {
-        connection->sk_tcp_nodelay_on = false;
-      }
-      else if (0 == setsockopt (s,
-                                IPPROTO_TCP,
-                                TCP_NODELAY,
-                                (const void *) &off_val,
-                                sizeof (off_val)))
-      {
-        connection->sk_tcp_nodelay_on = false;
-      }
+      MHD_send_socket_state_cork_nodelay_ (connection,
+                                           true,
+                                           false,
+                                           false,
+                                           false);
     }
 #elif TCP_NOPUSH
   /* We don't have MSG_MORE. The OS which implement NOPUSH implement
diff --git a/src/microhttpd/mhd_send.h b/src/microhttpd/mhd_send.h
index c4a6d705..c01d9357 100644
--- a/src/microhttpd/mhd_send.h
+++ b/src/microhttpd/mhd_send.h
@@ -86,4 +86,11 @@ MHD_send_socket_state_nopush_ (struct MHD_Connection 
*connection,
 void
 MHD_send_socket_state_nodelay_ (struct MHD_Connection *connection,
                                 bool value);
+
+void
+MHD_send_socket_state_cork_nodelay_ (struct MHD_Connection *connection,
+                                     bool cork_value,
+                                     bool cork_state,
+                                     bool nodelay_value,
+                                     bool nodelay_state);
 #endif /* MHD_SEND_H */

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

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