gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r37978 - libmicrohttpd/src/microhttpd
Date: Thu, 22 Sep 2016 16:33:39 +0200

Author: grothoff
Date: 2016-09-22 16:33:39 +0200 (Thu, 22 Sep 2016)
New Revision: 37978

Modified:
   libmicrohttpd/src/microhttpd/connection.c
   libmicrohttpd/src/microhttpd/daemon.c
   libmicrohttpd/src/microhttpd/internal.h
   libmicrohttpd/src/microhttpd/mhd_itc.c
   libmicrohttpd/src/microhttpd/mhd_itc.h
Log:
raising MHD_Pipe API abstraction level in preparation for fixing #3557

Modified: libmicrohttpd/src/microhttpd/connection.c
===================================================================
--- libmicrohttpd/src/microhttpd/connection.c   2016-09-22 12:19:15 UTC (rev 
37977)
+++ libmicrohttpd/src/microhttpd/connection.c   2016-09-22 14:33:39 UTC (rev 
37978)
@@ -520,8 +520,8 @@
      thread-per-connection mode, signal the main thread
      to resume accepting connections */
   if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
-       (MHD_INVALID_PIPE_ != daemon->wpipe[1]) &&
-       (1 != MHD_pipe_write_ (daemon->wpipe[1],
+       (! MHD_INVALID_PIPE_ (daemon->wpipe)) &&
+       (1 != MHD_pipe_write_ (daemon->wpipe,
                               "c",
                               1)) )
     {

Modified: libmicrohttpd/src/microhttpd/daemon.c
===================================================================
--- libmicrohttpd/src/microhttpd/daemon.c       2016-09-22 12:19:15 UTC (rev 
37977)
+++ libmicrohttpd/src/microhttpd/daemon.c       2016-09-22 14:33:39 UTC (rev 
37978)
@@ -1276,7 +1276,6 @@
   struct timeval *tvp;
   time_t now;
 #if WINDOWS
-  MHD_pipe spipe = daemon->wpipe[0];
 #ifdef HAVE_POLL
   int extra_slot;
 #endif /* HAVE_POLL */
@@ -1371,9 +1370,9 @@
              goto exit;
            }
 #if WINDOWS
-          if (MHD_INVALID_PIPE_ != spipe)
+          if (! MHD_INVALID_PIPE_(deamon->wpipe) )
             {
-              if (! MHD_add_to_fd_set_ (spipe,
+              if (! MHD_add_to_fd_set_ (MHD_pipe_get_read_fd_ (daemon->wpipe),
                                         &rs,
                                         &maxsock,
                                         FD_SETSIZE))
@@ -1410,10 +1409,10 @@
            }
 #if WINDOWS
           /* drain signaling pipe before other processing */
-          if ( (MHD_INVALID_PIPE_ != spipe) &&
-               (FD_ISSET (spipe,
+          if ( (! MHD_INVALID_PIPE_(daemon->wpipe)) &&
+               (FD_ISSET (MHD_pipe_get_read_fd_ (daemon->wpipe),
                           &rs)) )
-            MHD_pipe_drain_ (spipe);
+            MHD_pipe_drain_ (daemon->wpipe);
 #endif
           if (MHD_NO ==
               call_handlers (con,
@@ -1455,10 +1454,10 @@
            }
 #if WINDOWS
           extra_slot = 0;
-          if (MHD_INVALID_PIPE_ != spipe)
+          if (! MHD_INVALID_PIPE_(daemon->wpipe))
             {
               p[1].events |= POLLIN;
-              p[1].fd = spipe;
+              p[1].fd = MHD_pipe_get_read_fd_ (daemon->wpipe);
               p[1].revents = 0;
               extra_slot = 1;
             }
@@ -1482,9 +1481,9 @@
            }
 #if WINDOWS
           /* drain signaling pipe before other processing */
-          if ( (MHD_INVALID_PIPE_ != spipe) &&
+          if ( (! MHD_INVALID_PIPE_(daemon->wpipe)) &&
                (0 != (p[1].revents & (POLLERR | POLLHUP | POLLIN))) )
-            MHD_pipe_drain_ (spipe);
+            MHD_pipe_drain_ (daemon->wpipe);
 #endif
           if (MHD_NO ==
               call_handlers (con,
@@ -2025,8 +2024,8 @@
     }
   else
     if ( (MHD_YES == external_add) &&
-        (MHD_INVALID_PIPE_ != daemon->wpipe[1]) &&
-        (1 != MHD_pipe_write_ (daemon->wpipe[1],
+        (! MHD_INVALID_PIPE_(daemon->wpipe)) &&
+        (1 != MHD_pipe_write_ (daemon->wpipe,
                                 "n",
                                 1)) )
       {
@@ -2208,8 +2207,8 @@
     MHD_mutex_lock_ (&daemon->cleanup_connection_mutex);
   connection->resuming = MHD_YES;
   daemon->resuming = MHD_YES;
-  if ( (MHD_INVALID_PIPE_ != daemon->wpipe[1]) &&
-       (1 != MHD_pipe_write_ (daemon->wpipe[1], "r", 1)) )
+  if ( (! MHD_INVALID_PIPE_(daemon->wpipe)) &&
+       (1 != MHD_pipe_write_ (daemon->wpipe, "r", 1)) )
     {
 #ifdef HAVE_MESSAGES
       MHD_DLOG (daemon,
@@ -2703,10 +2702,10 @@
   /* drain signaling pipe to avoid spinning select */
   /* Do it before any other processing so new signals
      will trigger select again and will be processed */
-  if ((MHD_INVALID_PIPE_ != daemon->wpipe[0]) &&
-      (FD_ISSET (daemon->wpipe[0],
-                 read_fd_set)))
-    MHD_pipe_drain_ (daemon->wpipe[0]);
+  if ( (! MHD_INVALID_PIPE_(daemon->wpipe)) &&
+       (FD_ISSET (MHD_pipe_get_read_fd_ (daemon->wpipe),
+                  read_fd_set)) )
+    MHD_pipe_drain_ (daemon->wpipe);
 
   /* Resuming external connections when using an extern mainloop  */
   if (MHD_USE_SUSPEND_RESUME == (daemon->options & mask))
@@ -2839,8 +2838,8 @@
           return MHD_NO;
         }
     }
-  if ( (MHD_INVALID_PIPE_ != daemon->wpipe[0]) &&
-       (! MHD_add_to_fd_set_ (daemon->wpipe[0],
+  if ( (! MHD_INVALID_PIPE_(daemon->wpipe)) &&
+       (! MHD_add_to_fd_set_ (MHD_pipe_get_read_fd_ (daemon->wpipe),
                               &rs,
                               &maxsock,
                               FD_SETSIZE)) )
@@ -2876,7 +2875,7 @@
      only do this optimization if we have a signaling pipe in
      place. */
   if ( (MHD_INVALID_SOCKET != daemon->socket_fd) &&
-       (MHD_INVALID_PIPE_ != daemon->wpipe[0]) &&
+       (! MHD_INVALID_PIPE_(daemon->wpipe)) &&
        (0 != (daemon->options & MHD_USE_PIPE_FOR_SHUTDOWN)) &&
        ( (daemon->connections == daemon->connection_limit) ||
          (MHD_YES == daemon->at_limit) ) )
@@ -3001,9 +3000,9 @@
        poll_server++;
       }
     poll_pipe = -1;
-    if (MHD_INVALID_PIPE_ != daemon->wpipe[0])
+    if (! MHD_INVALID_PIPE_(daemon->wpipe))
       {
-       p[poll_server].fd = daemon->wpipe[0];
+       p[poll_server].fd = MHD_pipe_get_read_fd_ (daemon->wpipe);
        p[poll_server].events = POLLIN;
        p[poll_server].revents = 0;
         poll_pipe = (int) poll_server;
@@ -3087,7 +3086,7 @@
        new signals will be processed in next loop */
     if ( (-1 != poll_pipe) &&
          (0 != (p[poll_pipe].revents & POLLIN)) )
-      MHD_pipe_drain_ (daemon->wpipe[0]);
+      MHD_pipe_drain_ (daemon->wpipe);
 
     /* handle shutdown */
     if (MHD_YES == daemon->shutdown)
@@ -3182,9 +3181,9 @@
       poll_listen = poll_count;
       poll_count++;
     }
-  if (MHD_INVALID_PIPE_ != daemon->wpipe[0])
+  if (! MHD_INVALID_PIPE_(daemon->wpipe))
     {
-      p[poll_count].fd = daemon->wpipe[0];
+      p[poll_count].fd = MHD_pipe_get_read_fd_ (daemon->wpipe);
       p[poll_count].events = POLLIN;
       p[poll_count].revents = 0;
       poll_pipe = poll_count;
@@ -3213,7 +3212,7 @@
     }
   if ( (-1 != poll_pipe) &&
        (0 != (p[poll_pipe].revents & POLLIN)) )
-    MHD_pipe_drain_ (daemon->wpipe[0]);
+    MHD_pipe_drain_ (daemon->wpipe);
 
   /* handle shutdown */
   if (MHD_YES == daemon->shutdown)
@@ -3488,15 +3487,15 @@
 #endif
           /* UGH: we're storing pointers and fds in the same union
              here; incredibly ugly and somewhat risky, even though a
-             pointer with the same numeric value as the wpipe[0] can
+             pointer with the same numeric value as the wpipe.fd[0] can
              be expected to be rare... FIXME (a construction similar
              to what we did with the `upgrade_marker` should do) */
-          if ( (MHD_INVALID_PIPE_ != daemon->wpipe[0]) &&
-               (daemon->wpipe[0] == events[i].data.fd) )
+          if ( (! MHD_INVALID_PIPE_(daemon->wpipe)) &&
+               (MHD_pipe_get_read_fd_ (daemon->wpipe) == events[i].data.fd) )
             {
               /* It's OK to drain pipe here as all external
                  conditions will be processed later. */
-              MHD_pipe_drain_ (daemon->wpipe[0]);
+              MHD_pipe_drain_ (daemon->wpipe);
               continue;
             }
          if (daemon == events[i].data.ptr)
@@ -3759,7 +3758,7 @@
   ret = daemon->socket_fd;
   if (MHD_INVALID_SOCKET == ret)
     return MHD_INVALID_SOCKET;
-  if ( (MHD_INVALID_PIPE_ == daemon->wpipe[1]) &&
+  if ( (MHD_INVALID_PIPE_(daemon->wpipe)) &&
        (0 != (daemon->options & (MHD_USE_SELECT_INTERNALLY | 
MHD_USE_THREAD_PER_CONNECTION))) )
     {
 #ifdef HAVE_MESSAGES
@@ -3787,9 +3786,9 @@
          }
         else
 #endif
-        if (MHD_INVALID_PIPE_ != daemon->worker_pool[i].wpipe[1])
+        if (! MHD_INVALID_PIPE_(daemon->worker_pool[i].wpipe))
           {
-            if (1 != MHD_pipe_write_ (daemon->worker_pool[i].wpipe[1],
+            if (1 != MHD_pipe_write_ (daemon->worker_pool[i].wpipe,
                                       "q",
                                       1))
               MHD_PANIC (_("Failed to signal quiesce via pipe"));
@@ -3810,9 +3809,9 @@
     }
   else
 #endif
-  if (MHD_INVALID_PIPE_ != daemon->wpipe[1])
+    if (! MHD_INVALID_PIPE_(daemon->wpipe))
     {
-      if (1 != MHD_pipe_write_ (daemon->wpipe[1],
+      if (1 != MHD_pipe_write_ (daemon->wpipe,
                                 "q",
                                 1))
        MHD_PANIC (_("failed to signal quiesce via pipe"));
@@ -4325,15 +4324,15 @@
 #endif
       return MHD_NO;
     }
-  if ( (MHD_INVALID_PIPE_ != daemon->wpipe[0]) &&
+  if ( (! MHD_INVALID_PIPE_(daemon->wpipe)) &&
        (MHD_USE_SUSPEND_RESUME == (daemon->options & MHD_USE_SUSPEND_RESUME)) )
     {
       event.events = EPOLLIN | EPOLLET;
       event.data.ptr = NULL;
-      event.data.fd = daemon->wpipe[0];
+      event.data.fd = MHD_pipe_get_read_fd_ (daemon->wpipe);
       if (0 != epoll_ctl (daemon->epoll_fd,
                           EPOLL_CTL_ADD,
-                          daemon->wpipe[0],
+                          MHD_pipe_get_read_fd_ (daemon->wpipe),
                           &event))
         {
 #ifdef HAVE_MESSAGES
@@ -4440,8 +4439,7 @@
   daemon->pool_increment = MHD_BUF_INC_SIZE;
   daemon->unescape_callback = &unescape_wrapper;
   daemon->connection_timeout = 0;       /* no timeout */
-  daemon->wpipe[0] = MHD_INVALID_PIPE_;
-  daemon->wpipe[1] = MHD_INVALID_PIPE_;
+  MHD_make_invalid_pipe_ (daemon->wpipe);
 #ifdef SOMAXCONN
   daemon->listen_backlog_size = SOMAXCONN;
 #else  /* !SOMAXCONN */
@@ -4470,7 +4468,7 @@
       free (daemon);
       return NULL;
     }
-    if (! MHD_itc_nonblocking_(daemon->wpipe[0]))
+    if (! MHD_itc_nonblocking_ (daemon->wpipe))
       {
 #ifdef HAVE_MESSAGES
         MHD_DLOG (daemon,
@@ -4477,25 +4475,14 @@
                  _("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]))
-          MHD_PANIC (_("close failed\n"));
-        if (0 != MHD_pipe_close_ (daemon->wpipe[1]))
-          MHD_PANIC (_("close failed\n"));
+        MHD_pipe_close_ (daemon->wpipe);
         free (daemon);
         return NULL;
       }
-    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))) &&
        (1 == use_pipe) &&
-       (! MHD_SCKT_FD_FITS_FDSET_(daemon->wpipe[0],
+       (! MHD_SCKT_FD_FITS_FDSET_(MHD_pipe_get_read_fd_ (daemon->wpipe),
                                   NULL)) )
     {
 #ifdef HAVE_MESSAGES
@@ -4502,10 +4489,7 @@
       MHD_DLOG (daemon,
                _("file descriptor for control pipe exceeds maximum value\n"));
 #endif
-      if (0 != MHD_pipe_close_ (daemon->wpipe[0]))
-       MHD_PANIC (_("close failed\n"));
-      if (0 != MHD_pipe_close_ (daemon->wpipe[1]))
-       MHD_PANIC (_("close failed\n"));
+      MHD_pipe_close_ (daemon->wpipe);
       free (daemon);
       return NULL;
     }
@@ -5005,7 +4989,7 @@
 #endif
                   goto thread_failed;
                 }
-              if (! MHD_itc_nonblocking_(d->wpipe[0]))
+              if (! MHD_itc_nonblocking_(d->wpipe))
                 {
 #ifdef HAVE_MESSAGES
                   MHD_DLOG (daemon,
@@ -5014,17 +4998,9 @@
 #endif
                   goto thread_failed;
                 }
-              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))) &&
-               (! MHD_SCKT_FD_FITS_FDSET_(d->wpipe[0],
+               (! MHD_SCKT_FD_FITS_FDSET_(MHD_pipe_get_read_fd_ 
(daemon->wpipe),
                                           NULL)) )
             {
 #ifdef HAVE_MESSAGES
@@ -5031,10 +5007,7 @@
               MHD_DLOG (daemon,
                         _("File descriptor for worker control pipe exceeds 
maximum value\n"));
 #endif
-              if (0 != MHD_pipe_close_ (d->wpipe[0]))
-                MHD_PANIC (_("close failed\n"));
-              if (0 != MHD_pipe_close_ (d->wpipe[1]))
-                MHD_PANIC (_("close failed\n"));
+              MHD_pipe_close_ (d->wpipe);
               goto thread_failed;
             }
 
@@ -5140,12 +5113,8 @@
   if (0 != (flags & MHD_USE_SSL))
     gnutls_priority_deinit (daemon->priority_cache);
 #endif
-  if ( (MHD_INVALID_PIPE_ != daemon->wpipe[0]) &&
-       (0 != MHD_pipe_close_ (daemon->wpipe[0])) )
-    MHD_PANIC (_("close failed\n"));
-  if ( (MHD_INVALID_PIPE_ != daemon->wpipe[1]) &&
-       (0 != MHD_pipe_close_ (daemon->wpipe[1])) )
-    MHD_PANIC (_("close failed\n"));
+  if (! MHD_INVALID_PIPE_(daemon->wpipe))
+    MHD_pipe_close_ (daemon->wpipe);
   free (daemon);
   return NULL;
 }
@@ -5212,8 +5181,8 @@
       shutdown (pos->socket_fd, SHUT_RDWR);
 #if MHD_WINSOCK_SOCKETS
       if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
-           (MHD_INVALID_PIPE_ != daemon->wpipe[1]) &&
-           (1 != MHD_pipe_write_ (daemon->wpipe[1], "e", 1)) )
+           (! MHD_INVALID_PIPE_(daemon->wpipe)) &&
+           (1 != MHD_pipe_write_ (daemon->wpipe, "e", 1)) )
         MHD_PANIC (_("Failed to signal shutdown via pipe"));
 #endif
     }
@@ -5253,7 +5222,7 @@
 
 #ifdef EPOLL_SUPPORT
 /**
- * Shutdown epoll()-event loop by adding 'wpipe' to its event set.
+ * Shutdown epoll()-event loop by adding write end of 'wpipe' to its event set.
  *
  * @param daemon daemon of which the epoll() instance must be signalled
  */
@@ -5262,7 +5231,7 @@
 {
   struct epoll_event event;
 
-  if (MHD_INVALID_PIPE_ == daemon->wpipe[1])
+  if (MHD_INVALID_PIPE_(daemon->wpipe))
     {
       /* wpipe was required in this mode, how could this happen? */
       MHD_PANIC (_("Internal error\n"));
@@ -5271,7 +5240,7 @@
   event.data.ptr = NULL;
   if (0 != epoll_ctl (daemon->epoll_fd,
                      EPOLL_CTL_ADD,
-                     daemon->wpipe[1],
+                     MHD_pipe_get_write_fd_ (daemon->wpipe),
                      &event))
     MHD_PANIC (_("Failed to add wpipe to epoll set to signal termination\n"));
 }
@@ -5314,9 +5283,9 @@
 #endif
        }
     }
-  if (MHD_INVALID_PIPE_ != daemon->wpipe[1])
+  if (! MHD_INVALID_PIPE_(daemon->wpipe))
     {
-      if (1 != MHD_pipe_write_ (daemon->wpipe[1], "e", 1))
+      if (1 != MHD_pipe_write_ (daemon->wpipe, "e", 1))
        MHD_PANIC (_("Failed to signal shutdown via pipe"));
     }
 #ifdef HAVE_LISTEN_SHUTDOWN
@@ -5350,9 +5319,9 @@
       /* MHD_USE_NO_LISTEN_SOCKET disables thread pools, hence we need to 
check */
       for (i = 0; i < daemon->worker_pool_size; ++i)
        {
-         if (MHD_INVALID_PIPE_ != daemon->worker_pool[i].wpipe[1])
+         if (! MHD_INVALID_PIPE_(daemon->worker_pool[i].wpipe))
            {
-             if (1 != MHD_pipe_write_ (daemon->worker_pool[i].wpipe[1],
+             if (1 != MHD_pipe_write_ (daemon->worker_pool[i].wpipe,
                                         "e",
                                         1))
                MHD_PANIC (_("Failed to signal shutdown via pipe."));
@@ -5372,12 +5341,9 @@
           /* Individual pipes are always used */
           if (1)
             {
-              if (MHD_INVALID_PIPE_ != daemon->worker_pool[i].wpipe[1])
+              if (! MHD_INVALID_PIPE_ (daemon->worker_pool[i].wpipe) )
                 {
-                  if (0 != MHD_pipe_close_ (daemon->worker_pool[i].wpipe[0]))
-                    MHD_PANIC (_("close failed\n"));
-                  if (0 != MHD_pipe_close_ (daemon->worker_pool[i].wpipe[1]))
-                    MHD_PANIC (_("close failed\n"));
+                  MHD_pipe_close_ (daemon->worker_pool[i].wpipe);
                 }
            }
        }
@@ -5432,13 +5398,8 @@
   MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex);
   MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex);
 
-  if (MHD_INVALID_PIPE_ != daemon->wpipe[1])
-    {
-      if (0 != MHD_pipe_close_ (daemon->wpipe[0]))
-       MHD_PANIC (_("close failed\n"));
-      if (0 != MHD_pipe_close_ (daemon->wpipe[1]))
-       MHD_PANIC (_("close failed\n"));
-    }
+  if (! MHD_INVALID_PIPE_(daemon->wpipe))
+    MHD_pipe_close_ (daemon->wpipe);
   free (daemon);
 }
 

Modified: libmicrohttpd/src/microhttpd/internal.h
===================================================================
--- libmicrohttpd/src/microhttpd/internal.h     2016-09-22 12:19:15 UTC (rev 
37977)
+++ libmicrohttpd/src/microhttpd/internal.h     2016-09-22 14:33:39 UTC (rev 
37978)
@@ -1352,7 +1352,7 @@
    * MHD can be build with usage of socketpair instead of
    * pipe (forced on W32).
    */
-  MHD_pipe wpipe[2];
+  struct MHD_Pipe wpipe;
 
   /**
    * Are we shutting down?

Modified: libmicrohttpd/src/microhttpd/mhd_itc.c
===================================================================
--- libmicrohttpd/src/microhttpd/mhd_itc.c      2016-09-22 12:19:15 UTC (rev 
37977)
+++ libmicrohttpd/src/microhttpd/mhd_itc.c      2016-09-22 14:33:39 UTC (rev 
37978)
@@ -38,25 +38,29 @@
 /**
  * Change itc FD options to be non-blocking.
  *
- * @param fd the FD to manipulate
+ * @param pip the pipe to manipulate
  * @return non-zero if succeeded, zero otherwise
  */
 int
-MHD_itc_nonblocking_ (MHD_pipe fd)
+MHD_itc_nonblocking_ (struct MHD_Pipe pip)
 {
-  int flags;
+  unsigned int i;
 
-  flags = fcntl (fd,
-                 F_GETFL);
-  if (-1 == flags)
-    return 0;
+  for (i=0;i<2;i++)
+  {
+    int flags;
 
-  if ( ((flags | O_NONBLOCK) != flags) &&
-       (0 != fcntl (fd,
-                    F_SETFL,
-                    flags | O_NONBLOCK)) )
-    return 0;
+    flags = fcntl (pip.fd[i],
+                   F_GETFL);
+    if (-1 == flags)
+      return 0;
 
+    if ( ((flags | O_NONBLOCK) != flags) &&
+         (0 != fcntl (pip.fd[i],
+                      F_SETFL,
+                      flags | O_NONBLOCK)) )
+      return 0;
+  }
   return !0;
 }
 #endif /* _WIN32 && ! __CYGWIN__ */

Modified: libmicrohttpd/src/microhttpd/mhd_itc.h
===================================================================
--- libmicrohttpd/src/microhttpd/mhd_itc.h      2016-09-22 12:19:15 UTC (rev 
37977)
+++ libmicrohttpd/src/microhttpd/mhd_itc.h      2016-09-22 14:33:39 UTC (rev 
37978)
@@ -47,19 +47,25 @@
 #  include "mhd_sockets.h"
 #endif /* MHD_DONT_USE_PIPES */
 
-/* MHD_pipe is type for pipe FDs*/
+/**
+ * Data type for a MHD pipe.
+ */
+struct MHD_Pipe
+{
 #ifndef MHD_DONT_USE_PIPES
-  typedef int MHD_pipe;
+  int fd[2];
 #else /* ! MHD_DONT_USE_PIPES */
-  typedef MHD_socket MHD_pipe;
+  MHD_socket fd[2];
 #endif /* ! MHD_DONT_USE_PIPES */
+};
 
+
 /* MHD_pipe_ create pipe (!MHD_DONT_USE_PIPES) /
  *           create two connected sockets (MHD_DONT_USE_PIPES) */
 #ifndef MHD_DONT_USE_PIPES
-#  define MHD_pipe_(fdarr) (!pipe((fdarr)))
+#  define MHD_pipe_(pip) (!pipe((pip.fd)))
 #else /* MHD_DONT_USE_PIPES */
-#  define MHD_pipe_(fdarr) MHD_socket_pair_((fdarr))
+#  define MHD_pipe_(pip) MHD_socket_pair_((pip.fd))
 #endif /* MHD_DONT_USE_PIPES */
 
 /* MHD_pipe_last_strerror_ is description string of last errno 
(!MHD_DONT_USE_PIPES) /
@@ -73,35 +79,62 @@
 /* MHD_pipe_write_ write data to real pipe (!MHD_DONT_USE_PIPES) /
  *                 write data to emulated pipe (MHD_DONT_USE_PIPES) */
 #ifndef MHD_DONT_USE_PIPES
-#  define MHD_pipe_write_(fd, ptr, sz) write((fd), (const void*)(ptr), (sz))
+#  define MHD_pipe_write_(pip, ptr, sz) write((pip.fd[1]), (const void*)(ptr), 
(sz))
 #else
-#  define MHD_pipe_write_(fd, ptr, sz) send((fd), (const char*)(ptr), (sz), 0)
+#  define MHD_pipe_write_(pip, ptr, sz) send((pip.fd[1]), (const char*)(ptr), 
(sz), 0)
 #endif
 
+
+#ifndef MHD_DONT_USE_PIPES
+#  define MHD_pipe_get_read_fd_(pip) (pip.fd[0])
+#else
+#  define MHD_pipe_get_read_fd_(pip) (pip.fd[0])
+#endif
+
+
+#ifndef MHD_DONT_USE_PIPES
+#  define MHD_pipe_get_write_fd_(pip) (pip.fd[1])
+#else
+#  define MHD_pipe_get_write_fd_(pip) (pip.fd[1])
+#endif
+
+
+
 /* MHD_pipe_drain_ drain data from real pipe (!MHD_DONT_USE_PIPES) /
  *                drain data from emulated pipe (MHD_DONT_USE_PIPES) */
 #ifndef MHD_DONT_USE_PIPES
-#  define MHD_pipe_drain_(fd) do { long tmp; while (0 < read((fd), 
(void*)&tmp, sizeof (tmp))) ; } while (0)
+#  define MHD_pipe_drain_(pip) do { long tmp; while (0 < read((pip.fd[0]), 
(void*)&tmp, sizeof (tmp))) ; } while (0)
 #else
-#  define MHD_pipe_drain_(fd) do { long tmp; while (0 < recv((fd), 
(void*)&tmp, sizeof (tmp), 0)) ; } while (0)
+#  define MHD_pipe_drain_(pip) do { long tmp; while (0 < recv((pip.fd[0]), 
(void*)&tmp, sizeof (tmp), 0)) ; } while (0)
 #endif
 
 /* MHD_pipe_close_(fd) close any FDs (non-W32) /
  *                     close emulated pipe FDs (W32) */
 #ifndef MHD_DONT_USE_PIPES
-#  define MHD_pipe_close_(fd) close((fd))
+#  define MHD_pipe_close_(pip) do { close(pip.fd[0]); close(pip.fd[1]); } 
while (0)
 #else
-#  define MHD_pipe_close_(fd) MHD_socket_close_((fd))
+#  define MHD_pipe_close_(fd) do { MHD_socket_close_(pip.fd[0]); 
MHD_socket_close_(pip.fd[1]); } while (0)
 #endif
 
 /* MHD_INVALID_PIPE_ is a value of bad pipe FD */
 #ifndef MHD_DONT_USE_PIPES
-#  define MHD_INVALID_PIPE_ (-1)
+#  define MHD_INVALID_PIPE_(pip)  (-1 == pip.fd[0])
 #else
-#  define MHD_INVALID_PIPE_ MHD_INVALID_SOCKET
+#  define MHD_INVALID_PIPE_(pip)  (MHD_INVALID_SOCKET == pip.fd[0])
 #endif
 
 #ifndef MHD_DONT_USE_PIPES
+#define MHD_make_invalid_pipe_(pip) do { \
+    pip.fd[0] = pip.fd[1] = -1; \
+  } while (0)
+#else
+#define MHD_make_invalid_pipe_(pip) do { \
+    pip.fd[0] = pip.fd[1] = MHD_INVALID_SOCKET; \
+  } while (0)
+#endif
+
+
+#ifndef MHD_DONT_USE_PIPES
 /**
  * Change itc FD options to be non-blocking.
  *
@@ -108,10 +141,10 @@
  * @param fd the FD to manipulate
  * @return non-zero if succeeded, zero otherwise
  */
-   int
-   MHD_itc_nonblocking_ (MHD_pipe fd);
+int
+MHD_itc_nonblocking_ (struct MHD_Pipe fd);
 #else
-#  define MHD_itc_nonblocking_(f) MHD_socket_nonblocking_((f))
+#  define MHD_itc_nonblocking_(pip) (MHD_socket_nonblocking_((pip.fd[0])) && 
MHD_socket_nonblocking_((pip.fd[1])))
 #endif
 
 #endif /* MHD_ITC_H */




reply via email to

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