gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r37887 - libmicrohttpd/src/microhttpd


From: gnunet
Subject: [GNUnet-SVN] r37887 - libmicrohttpd/src/microhttpd
Date: Mon, 5 Sep 2016 14:15:43 +0200

Author: grothoff
Date: 2016-09-05 14:15:43 +0200 (Mon, 05 Sep 2016)
New Revision: 37887

Modified:
   libmicrohttpd/src/microhttpd/basicauth.c
   libmicrohttpd/src/microhttpd/connection.c
Log:
-remove duplicated socket_start_no_buffering logic in 
socket_start_no_buffering_flash

Modified: libmicrohttpd/src/microhttpd/basicauth.c
===================================================================
--- libmicrohttpd/src/microhttpd/basicauth.c    2016-09-05 12:04:54 UTC (rev 
37886)
+++ libmicrohttpd/src/microhttpd/basicauth.c    2016-09-05 12:15:43 UTC (rev 
37887)
@@ -55,7 +55,9 @@
   if ( (NULL == (header = MHD_lookup_connection_value (connection,
                                                       MHD_HEADER_KIND,
                                                       
MHD_HTTP_HEADER_AUTHORIZATION))) ||
-       (0 != strncmp (header, _BASIC_BASE, strlen(_BASIC_BASE))) )
+       (0 != strncmp (header,
+                      _BASIC_BASE,
+                      strlen (_BASIC_BASE))) )
     return NULL;
   header += strlen (_BASIC_BASE);
   if (NULL == (decode = BASE64Decode (header)))
@@ -67,11 +69,12 @@
       return NULL;
     }
   /* Find user:password pattern */
-  if (NULL == (separator = strchr (decode, ':')))
+  if (NULL == (separator = strchr (decode,
+                                   ':')))
     {
 #ifdef HAVE_MESSAGES
       MHD_DLOG(connection->daemon,
-              "Basic authentication doesn't contain ':' separator\n");
+              _("Basic authentication doesn't contain ':' separator\n"));
 #endif
       free (decode);
       return NULL;
@@ -89,7 +92,7 @@
        {
 #ifdef HAVE_MESSAGES
          MHD_DLOG(connection->daemon,
-                  "Failed to allocate memory for password\n");
+                  _("Failed to allocate memory for password\n"));
 #endif
          free (decode);
          free (user);
@@ -123,7 +126,7 @@
   size_t hlen = strlen(realm) + strlen("Basic realm=\"\"") + 1;
   char *header;
 
-  header = (char*)malloc(hlen);
+  header = (char *) malloc(hlen);
   if (NULL == header)
   {
 #ifdef HAVE_MESSAGES
@@ -152,7 +155,7 @@
     {
 #ifdef HAVE_MESSAGES
       MHD_DLOG (connection->daemon,
-                "Failed to add Basic auth header\n");
+                _("Failed to add Basic auth header\n"));
 #endif /* HAVE_MESSAGES */
     }
   return ret;

Modified: libmicrohttpd/src/microhttpd/connection.c
===================================================================
--- libmicrohttpd/src/microhttpd/connection.c   2016-09-05 12:04:54 UTC (rev 
37886)
+++ libmicrohttpd/src/microhttpd/connection.c   2016-09-05 12:15:43 UTC (rev 
37887)
@@ -154,13 +154,21 @@
     return MHD_NO;
 #if defined(TCP_NOPUSH) && !defined(TCP_CORK)
   /* Buffer data before sending */
-  res = (0 == setsockopt (connection->socket_fd, IPPROTO_TCP, TCP_NOPUSH, 
(const void*)&on_val,
-                          sizeof (on_val))) ? MHD_YES : MHD_NO;
+  res = (0 == setsockopt (connection->socket_fd,
+                          IPPROTO_TCP,
+                          TCP_NOPUSH,
+                          (const void *) &on_val,
+                          sizeof (on_val)))
+    ? MHD_YES : MHD_NO;
 #if defined(TCP_NODELAY)
   /* Enable Nagle's algorithm */
   /* TCP_NODELAY may interfere with TCP_NOPUSH */
-  res &= (0 == setsockopt (connection->socket_fd, IPPROTO_TCP, TCP_NODELAY, 
(const void*)&off_val,
-                           sizeof (off_val))) ? MHD_YES : MHD_NO;
+  res &= (0 == setsockopt (connection->socket_fd,
+                           IPPROTO_TCP,
+                           TCP_NODELAY,
+                           (const void *) &off_val,
+                           sizeof (off_val)))
+    ? MHD_YES : MHD_NO;
 #endif /* TCP_NODELAY */
 #else /* TCP_CORK */
 #if defined(TCP_NODELAY)
@@ -167,12 +175,19 @@
   /* Enable Nagle's algorithm */
   /* TCP_NODELAY may prevent enabling TCP_CORK. Resulting buffering mode 
depends
      solely on TCP_CORK result, so ignoring return code here. */
-  (void)setsockopt (connection->socket_fd, IPPROTO_TCP, TCP_NODELAY, (const 
void*)&off_val,
-                    sizeof (off_val));
+  (void) setsockopt (connection->socket_fd,
+                     IPPROTO_TCP,
+                     TCP_NODELAY,
+                     (const void *) &off_val,
+                     sizeof (off_val));
 #endif /* TCP_NODELAY */
   /* Send only full packets */
-  res = (0 == setsockopt (connection->socket_fd, IPPROTO_TCP, TCP_CORK, (const 
void*)&on_val,
-                          sizeof (on_val))) ? MHD_YES : MHD_NO;
+  res = (0 == setsockopt (connection->socket_fd,
+                          IPPROTO_TCP,
+                          TCP_CORK,
+                          (const void *) &on_val,
+                          sizeof (on_val)))
+    ? MHD_YES : MHD_NO;
 #endif /* TCP_CORK */
 #endif /* TCP_CORK || TCP_NOPUSH */
   return res;
@@ -180,88 +195,86 @@
 
 
 /**
- * Activate no buffering mode (no delay sending) on connection socket
- * and push to client data pending in socket buffer.
+ * Activate no buffering mode (no delay sending) on connection socket.
  *
  * @param connection connection to be processed
  * @return #MHD_YES on success, #MHD_NO otherwise
  */
 static int
-socket_start_no_buffering_flush (struct MHD_Connection *connection)
+socket_start_no_buffering (struct MHD_Connection *connection)
 {
+#if defined(TCP_NODELAY)
+  int res = MHD_YES;
+  const MHD_SCKT_OPT_BOOL_ on_val = 1;
 #if defined(TCP_CORK) || defined(TCP_NOPUSH)
-  int res = MHD_YES;
   const MHD_SCKT_OPT_BOOL_ off_val = 0;
-#if defined(TCP_NODELAY)
-  const MHD_SCKT_OPT_BOOL_ on_val = 1;
-#endif /* TCP_NODELAY */
-#if !defined(TCP_CORK)
-  const int dummy = 0;
-#endif /* !TCP_CORK */
-  if (!connection)
+#endif /* TCP_CORK || TCP_NOPUSH */
+
+  if (NULL == connection)
     return MHD_NO;
 #if defined(TCP_CORK)
-  /* Flush buffered data, allow partial packets */
-  res &= (0 == setsockopt (connection->socket_fd, IPPROTO_TCP, TCP_CORK, 
(const void*)&off_val,
-                          sizeof (off_val))) ? MHD_YES : MHD_NO;
+  /* Allow partial packets */
+  res &= (0 == setsockopt (connection->socket_fd,
+                           IPPROTO_TCP,
+                           TCP_CORK,
+                           (const void *) &off_val,
+                           sizeof (off_val)))
+    ? MHD_YES : MHD_NO;
 #endif /* TCP_CORK */
 #if defined(TCP_NODELAY)
-  /* Disable Nagle's algorithm */
-  res &= (0 == setsockopt (connection->socket_fd, IPPROTO_TCP, TCP_NODELAY, 
(const void*)&on_val,
-                           sizeof (on_val))) ? MHD_YES : MHD_NO;
+  /* Disable Nagle's algorithm for sending packets without delay */
+  res &= (0 == setsockopt (connection->socket_fd,
+                           IPPROTO_TCP,
+                           TCP_NODELAY,
+                           (const void *) &on_val,
+                           sizeof (on_val)))
+    ? MHD_YES : MHD_NO;
 #endif /* TCP_NODELAY */
 #if defined(TCP_NOPUSH) && !defined(TCP_CORK)
-  /* Send data without extra buffering, may flush pending data on some 
platforms */
-  res &= (0 == setsockopt (connection->socket_fd, IPPROTO_TCP, TCP_NOPUSH, 
(const void*)&off_val,
-                           sizeof (off_val))) ? MHD_YES : MHD_NO;
-  /* Force flush data with zero send otherwise Darwin and some BSD systems
-     will add 5 seconds delay. Not required with TCP_CORK as switching off
-     TCP_CORK always flushes socket buffer. */
-  res &= (0 <= send (connection->socket_fd, (const void*)&dummy, 0, 0)) ? 
MHD_YES : MHD_NO;
-#endif /* TCP_NOPUSH && !TCP_CORK*/
+  /* Disable extra buffering */
+  res &= (0 == setsockopt (connection->socket_fd,
+                           IPPROTO_TCP,
+                           TCP_NOPUSH,
+                           (const void *) &off_val,
+                           sizeof (off_val)))
+    ? MHD_YES : MHD_NO;
+#endif /* TCP_NOPUSH  && !TCP_CORK */
   return res;
-#else  /* !TCP_CORK && !TCP_NOPUSH */
+#else  /* !TCP_NODELAY */
   return MHD_NO;
-#endif /* !TCP_CORK && !TCP_NOPUSH */
+#endif /* !TCP_NODELAY */
 }
 
 
 /**
- * Activate no buffering mode (no delay sending) on connection socket.
+ * Activate no buffering mode (no delay sending) on connection socket
+ * and push to client data pending in socket buffer.
  *
  * @param connection connection to be processed
  * @return #MHD_YES on success, #MHD_NO otherwise
  */
 static int
-socket_start_no_buffering (struct MHD_Connection *connection)
+socket_start_no_buffering_flush (struct MHD_Connection *connection)
 {
-#if defined(TCP_NODELAY)
   int res = MHD_YES;
-  const MHD_SCKT_OPT_BOOL_ on_val = 1;
-#if defined(TCP_CORK) || defined(TCP_NOPUSH)
-  const MHD_SCKT_OPT_BOOL_ off_val = 0;
-#endif /* TCP_CORK || TCP_NOPUSH */
-  if (!connection)
+#if defined(TCP_NOPUSH) && !defined(TCP_CORK)
+  const int dummy = 0;
+#endif /* !TCP_CORK */
+
+  if (NULL == connection)
     return MHD_NO;
-#if defined(TCP_CORK)
-  /* Allow partial packets */
-  res &= (0 == setsockopt (connection->socket_fd, IPPROTO_TCP, TCP_CORK, 
(const void*)&off_val,
-                          sizeof (off_val))) ? MHD_YES : MHD_NO;
-#endif /* TCP_CORK */
-#if defined(TCP_NODELAY)
-  /* Disable Nagle's algorithm for sending packets without delay */
-  res &= (0 == setsockopt (connection->socket_fd, IPPROTO_TCP, TCP_NODELAY, 
(const void*)&on_val,
-                           sizeof (on_val))) ? MHD_YES : MHD_NO;
-#endif /* TCP_NODELAY */
+  res = socket_start_no_buffering (connection);
 #if defined(TCP_NOPUSH) && !defined(TCP_CORK)
-  /* Disable extra buffering */
-  res &= (0 == setsockopt (connection->socket_fd, IPPROTO_TCP, TCP_NOPUSH, 
(const void*)&off_val,
-                           sizeof (off_val))) ? MHD_YES : MHD_NO;
-#endif /* TCP_NOPUSH  && !TCP_CORK */
+  /* Force flush data with zero send otherwise Darwin and some BSD systems
+     will add 5 seconds delay. Not required with TCP_CORK as switching off
+     TCP_CORK always flushes socket buffer. */
+  res &= (0 <= send (connection->socket_fd,
+                     (const void *) &dummy,
+                     0,
+                     0))
+    ? MHD_YES : MHD_NO;
+#endif /* TCP_NOPUSH && !TCP_CORK*/
   return res;
-#else  /* !TCP_NODELAY */
-  return MHD_NO;
-#endif /* !TCP_NODELAY */
 }
 
 
@@ -287,20 +300,36 @@
   /* Allow partial packets */
   /* Disabling TCP_CORK will flush partial packet even if TCP_CORK wasn't 
enabled before
      so try to check current value of TCP_CORK to prevent unrequested flushing 
*/
-  if ( (0 != getsockopt (connection->socket_fd, IPPROTO_TCP, TCP_CORK, 
(void*)&cork_val, &param_size)) ||
+  if ( (0 != getsockopt (connection->socket_fd,
+                         IPPROTO_TCP,
+                         TCP_CORK,
+                         (void*)&cork_val,
+                         &param_size)) ||
        (0 != cork_val))
-    res &= (0 == setsockopt (connection->socket_fd, IPPROTO_TCP, TCP_CORK, 
(const void*)&off_val,
-                             sizeof (off_val))) ? MHD_YES : MHD_NO;
+    res &= (0 == setsockopt (connection->socket_fd,
+                             IPPROTO_TCP,
+                             TCP_CORK,
+                             (const void *) &off_val,
+                             sizeof (off_val)))
+      ? MHD_YES : MHD_NO;
 #elif defined(TCP_NOPUSH)
   /* Disable extra buffering */
   /* No need to check current value as disabling TCP_NOPUSH will not flush 
partial
      packet if TCP_NOPUSH wasn't enabled before */
-  res &= (0 == setsockopt (connection->socket_fd, IPPROTO_TCP, TCP_NOPUSH, 
(const void*)&off_val,
-                           sizeof (off_val))) ? MHD_YES : MHD_NO;
+  res &= (0 == setsockopt (connection->socket_fd,
+                           IPPROTO_TCP,
+                           TCP_NOPUSH,
+                           (const void *) &off_val,
+                           sizeof (off_val)))
+    ? MHD_YES : MHD_NO;
 #endif /* TCP_NOPUSH && !TCP_CORK */
   /* Enable Nagle's algorithm for normal buffering */
-  res &= (0 == setsockopt (connection->socket_fd, IPPROTO_TCP, TCP_NODELAY, 
(const void*)&off_val,
-                           sizeof (off_val))) ? MHD_YES : MHD_NO;
+  res &= (0 == setsockopt (connection->socket_fd,
+                           IPPROTO_TCP,
+                           TCP_NODELAY,
+                           (const void *) &off_val,
+                           sizeof (off_val)))
+    ? MHD_YES : MHD_NO;
   return res;
 #else  /* !TCP_NODELAY */
   return MHD_NO;




reply via email to

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