gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r37771 - in libmicrohttpd: . src/microhttpd


From: gnunet
Subject: [GNUnet-SVN] r37771 - in libmicrohttpd: . src/microhttpd
Date: Tue, 23 Aug 2016 22:13:26 +0200

Author: Karlson2k
Date: 2016-08-23 22:13:26 +0200 (Tue, 23 Aug 2016)
New Revision: 37771

Modified:
   libmicrohttpd/configure.ac
   libmicrohttpd/src/microhttpd/daemon.c
   libmicrohttpd/src/microhttpd/mhd_itc.c
   libmicrohttpd/src/microhttpd/mhd_itc.h
   libmicrohttpd/src/microhttpd/mhd_sockets.c
   libmicrohttpd/src/microhttpd/mhd_sockets.h
Log:
Moved make_nonblocking() to mhd_sockets.c, added MHD_itc_nonblocking() for 
pipes.

Modified: libmicrohttpd/configure.ac
===================================================================
--- libmicrohttpd/configure.ac  2016-08-23 20:13:23 UTC (rev 37770)
+++ libmicrohttpd/configure.ac  2016-08-23 20:13:26 UTC (rev 37771)
@@ -547,7 +547,7 @@
 # Check for optional headers
 AC_CHECK_HEADERS([sys/types.h sys/time.h sys/msg.h netdb.h netinet/in.h 
netinet/tcp.h time.h sys/socket.h sys/mman.h arpa/inet.h sys/select.h search.h \
   endian.h machine/endian.h sys/endian.h sys/param.h sys/machine.h 
sys/byteorder.h machine/param.h sys/isa_defs.h \
-  inttypes.h stddef.h \
+  inttypes.h stddef.h unistd.h \
   sockLib.h inetLib.h net/if.h])
 AM_CONDITIONAL([HAVE_TSEARCH], [test "x$ac_cv_header_search_h" = "xyes"])
 

Modified: libmicrohttpd/src/microhttpd/daemon.c
===================================================================
--- libmicrohttpd/src/microhttpd/daemon.c       2016-08-23 20:13:23 UTC (rev 
37770)
+++ libmicrohttpd/src/microhttpd/daemon.c       2016-08-23 20:13:26 UTC (rev 
37771)
@@ -136,49 +136,6 @@
 
 
 /**
- * Change socket options to be non-blocking.
- *
- * @param daemon daemon context
- * @param sock socket to manipulate
- * @return #MHD_YES if succeeded, #MHD_NO otherwise
- */
-static int
-make_nonblocking (struct MHD_Daemon *daemon,
-                  MHD_socket sock)
-{
-#ifdef MHD_WINSOCK_SOCKETS
-  unsigned long flags = 1;
-
-  if (0 != ioctlsocket (sock, FIONBIO, &flags))
-    {
- #ifdef HAVE_MESSAGES
-      MHD_DLOG (daemon,
-                "Failed to make socket non-blocking: %s\n",
-                MHD_socket_last_strerr_ ());
- #endif
-      return MHD_NO;
-    }
-#else  /* MHD_POSIX_SOCKETS */
-  int flags;
-
-  flags = fcntl (sock, F_GETFL);
-  if ( ( (-1 == flags) ||
-        ( (flags != (flags | O_NONBLOCK)) &&
-          (0 != fcntl (sock, F_SETFL, flags | O_NONBLOCK)) ) ) )
-    {
-#ifdef HAVE_MESSAGES
-      MHD_DLOG (daemon,
-                "Failed to make socket non-blocking: %s\n",
-                MHD_socket_last_strerr_ ());
-#endif
-      return MHD_NO;
-    }
-#endif /* MHD_POSIX_SOCKETS */
-  return MHD_YES;
-}
-
-
-/**
  * Trace up to and return master daemon. If the supplied daemon
  * is a master, then return the daemon itself.
  *
@@ -1420,7 +1377,14 @@
     {
       /* in turbo mode, we assume that non-blocking was already set
         by 'accept4' or whoever calls 'MHD_add_connection' */
-      make_nonblocking (daemon, connection->socket_fd);
+      if (!MHD_socket_nonblocking_ (connection->socket_fd))
+        {
+#ifdef HAVE_MESSAGES
+          MHD_DLOG (connection->daemon,
+                    "Failed to set nonblocking mode on connection socket: 
%s\n",
+                    MHD_socket_last_strerr_());
+#endif
+        }
     }
 
 #if HTTPS_SUPPORT
@@ -1839,7 +1803,7 @@
 make_nonblocking_noninheritable (struct MHD_Daemon *daemon,
                                 MHD_socket sock)
 {
-  (void)make_nonblocking (daemon, sock);
+  (void)MHD_socket_nonblocking_(sock);
   (void)make_noninheritable (daemon, sock);
 }
 
@@ -1974,7 +1938,14 @@
 #if !defined(USE_ACCEPT4)
   make_nonblocking_noninheritable (daemon, s);
 #elif !defined(HAVE_SOCK_NONBLOCK)
-  make_nonblocking (daemon, s);
+  if (!MHD_socket_nonblocking_ (s))
+    {
+#ifdef HAVE_MESSAGES
+      MHD_DLOG (daemon,
+                "Failed to set nonblocking mode on incoming connection socket: 
%s\n",
+                MHD_socket_last_strerr_());
+#endif
+    }
 #elif !defined(SOCK_CLOEXEC)
   make_noninheritable (daemon, s);
 #endif
@@ -3711,11 +3682,11 @@
       free (daemon);
       return NULL;
     }
-    if (MHD_NO == make_nonblocking (daemon, daemon->wpipe[0]))
+    if (!MHD_itc_nonblocking_(daemon->wpipe[0]))
       {
 #ifdef HAVE_MESSAGES
         MHD_DLOG (daemon,
-                 "Failed to make control pipe non-blocking: %s\n",
+                 "Failed to make read side of inter-thread control channel 
non-blocking: %s\n",
                  MHD_pipe_last_strerror_ ());
 #endif
         if (0 != MHD_pipe_close_ (daemon->wpipe[0]))
@@ -3725,7 +3696,14 @@
         free (daemon);
         return NULL;
       }
-    make_nonblocking (daemon, daemon->wpipe[1]);
+    if (!MHD_itc_nonblocking_(daemon->wpipe[1]))
+      {
+#ifdef HAVE_MESSAGES
+        MHD_DLOG (daemon,
+                  "Failed to make write side of inter-thread control channel 
non-blocking: %s\n",
+                  MHD_pipe_last_strerror_ ());
+#endif
+      }
   }
   if ( (0 == (flags & (MHD_USE_POLL | MHD_USE_EPOLL_LINUX_ONLY))) &&
        (1 == use_pipe) &&
@@ -4071,8 +4049,13 @@
       socket_fd = daemon->socket_fd;
     }
 
-  if (MHD_NO == make_nonblocking (daemon, socket_fd))
+  if (!MHD_socket_nonblocking_ (socket_fd))
     {
+#ifdef HAVE_MESSAGES
+      MHD_DLOG (daemon,
+                "Failed to set nonblocking mode on listening socket: %s\n",
+                MHD_socket_last_strerr_());
+#endif
       if (0 != (flags & MHD_USE_EPOLL_LINUX_ONLY) ||
           daemon->worker_pool_size > 0)
         {
@@ -4233,16 +4216,23 @@
 #endif
                   goto thread_failed;
                 }
-              if (MHD_NO == make_nonblocking (d, d->wpipe[0]))
+              if (!MHD_itc_nonblocking_(d->wpipe[0]))
                 {
 #ifdef HAVE_MESSAGES
                   MHD_DLOG (daemon,
-                            "Failed to make worker control pipe non_blocking: 
%s\n",
-                            MHD_pipe_last_strerror_() );
+                            "Failed to make read side of worker inter-thread 
control channel non-blocking: %s\n",
+                            MHD_pipe_last_strerror_ ());
 #endif
                   goto thread_failed;
                 }
-              make_nonblocking (d, d->wpipe[1]);
+              if (!MHD_itc_nonblocking_(d->wpipe[1]))
+                {
+#ifdef HAVE_MESSAGES
+                  MHD_DLOG (daemon,
+                            "Failed to make write side of worker inter-thread 
control channel non-blocking: %s\n",
+                            MHD_pipe_last_strerror_ ());
+#endif
+                }
             }
           if ( (0 == (flags & (MHD_USE_POLL | MHD_USE_EPOLL_LINUX_ONLY))) &&
                (!MHD_SCKT_FD_FITS_FDSET_(d->wpipe[0], NULL)) )

Modified: libmicrohttpd/src/microhttpd/mhd_itc.c
===================================================================
--- libmicrohttpd/src/microhttpd/mhd_itc.c      2016-08-23 20:13:23 UTC (rev 
37770)
+++ libmicrohttpd/src/microhttpd/mhd_itc.c      2016-08-23 20:13:26 UTC (rev 
37771)
@@ -26,6 +26,11 @@
 
 #include "mhd_itc.h"
 
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif /* HAVE_UNISTD_H */
+#include <fcntl.h>
+
 #if defined(_WIN32) && !defined(__CYGWIN__)
 /**
  * Create pair of mutually connected TCP/IP sockets on loopback address
@@ -106,3 +111,31 @@
 }
 
 #endif /* _WIN32 && ! __CYGWIN__ */
+
+#ifndef MHD_DONT_USE_PIPES
+#if !defined(_WIN32) || defined(__CYGWIN__)
+
+
+/**
+ * Change itc FD options to be non-blocking.
+ *
+ * @param fd the FD to manipulate
+ * @return non-zero if succeeded, zero otherwise
+ */
+int
+MHD_itc_nonblocking_ (MHD_pipe fd)
+{
+  int flags;
+
+  flags = fcntl (fd, F_GETFL);
+  if (-1 == flags)
+    return 0;
+
+  if ( ((flags | O_NONBLOCK) != flags) &&
+       (0 != fcntl (fd, F_SETFL, flags | O_NONBLOCK)) )
+    return 0;
+
+  return !0;
+}
+#endif /* _WIN32 && ! __CYGWIN__ */
+#endif /* ! MHD_DONT_USE_PIPES */

Modified: libmicrohttpd/src/microhttpd/mhd_itc.h
===================================================================
--- libmicrohttpd/src/microhttpd/mhd_itc.h      2016-08-23 20:13:23 UTC (rev 
37770)
+++ libmicrohttpd/src/microhttpd/mhd_itc.h      2016-08-23 20:13:26 UTC (rev 
37771)
@@ -114,5 +114,17 @@
 int MHD_W32_pair_of_sockets_(SOCKET sockets_pair[2]);
 #endif /* _WIN32 && ! __CYGWIN__ */
 
+#ifndef MHD_DONT_USE_PIPES
+/**
+ * Change itc FD options to be non-blocking.
+ *
+ * @param fd the FD to manipulate
+ * @return non-zero if succeeded, zero otherwise
+ */
+   int
+   MHD_itc_nonblocking_ (MHD_pipe fd);
+#else
+#  define MHD_itc_nonblocking_(f) MHD_socket_nonblocking_((f))
+#endif
 
 #endif /* MHD_ITC_H */

Modified: libmicrohttpd/src/microhttpd/mhd_sockets.c
===================================================================
--- libmicrohttpd/src/microhttpd/mhd_sockets.c  2016-08-23 20:13:23 UTC (rev 
37770)
+++ libmicrohttpd/src/microhttpd/mhd_sockets.c  2016-08-23 20:13:26 UTC (rev 
37771)
@@ -25,6 +25,10 @@
  */
 
 #include "mhd_sockets.h"
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif /* HAVE_UNISTD_H */
+#include <fcntl.h>
 
 #ifdef MHD_WINSOCK_SOCKETS
 
@@ -264,3 +268,32 @@
 
   return !0;
 }
+
+
+/**
+ * Change socket options to be non-blocking.
+ *
+ * @param sock socket to manipulate
+ * @return non-zero if succeeded, zero otherwise
+ */
+int
+MHD_socket_nonblocking_ (MHD_socket sock)
+{
+#if defined(MHD_POSIX_SOCKETS)
+  int flags;
+
+  flags = fcntl (sock, F_GETFL);
+  if (-1 == flags)
+    return 0;
+
+  if ( ((flags | O_NONBLOCK) != flags) &&
+       (0 != fcntl (sock, F_SETFL, flags | O_NONBLOCK)) )
+    return 0;
+#elif defined(MHD_WINSOCK_SOCKETS)
+  unsigned long flags = 1;
+
+  if (0 != ioctlsocket (sock, FIONBIO, &flags))
+    return 0;
+#endif /* MHD_WINSOCK_SOCKETS */
+  return !0;
+}

Modified: libmicrohttpd/src/microhttpd/mhd_sockets.h
===================================================================
--- libmicrohttpd/src/microhttpd/mhd_sockets.h  2016-08-23 20:13:23 UTC (rev 
37770)
+++ libmicrohttpd/src/microhttpd/mhd_sockets.h  2016-08-23 20:13:26 UTC (rev 
37771)
@@ -586,4 +586,15 @@
                     fd_set *set,
                     MHD_socket *max_fd,
                     unsigned int fd_setsize);
+
+
+/**
+ * Change socket options to be non-blocking.
+ *
+ * @param sock socket to manipulate
+ * @return non-zero if succeeded, zero otherwise
+ */
+int
+MHD_socket_nonblocking_ (MHD_socket sock);
+
 #endif /* ! MHD_SOCKETS_H */




reply via email to

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