gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r38114 - in libmicrohttpd: src/microhttpd w32/common


From: gnunet
Subject: [GNUnet-SVN] r38114 - in libmicrohttpd: src/microhttpd w32/common
Date: Tue, 11 Oct 2016 17:21:11 +0200

Author: Karlson2k
Date: 2016-10-11 17:21:11 +0200 (Tue, 11 Oct 2016)
New Revision: 38114

Added:
   libmicrohttpd/src/microhttpd/mhd_itc_types.h
Modified:
   libmicrohttpd/src/microhttpd/Makefile.am
   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
   libmicrohttpd/w32/common/libmicrohttpd-files.vcxproj
   libmicrohttpd/w32/common/libmicrohttpd-filters.vcxproj
Log:
Use MHD_itc_activate_ macro for ITC signaling, move ITC types to separate
header.
Separate header allow exclusion of heavy headers in internal.h, which is
included by most source files.
Fixed checking success of write() to eventFD by comparing result to 1.
Fixed error when trying to signal on fully filled ITC (ITC is already in
activated (signaled) state and those conditions are not an error).
EventFD is signaled now by macro, not a function.

Modified: libmicrohttpd/src/microhttpd/Makefile.am
===================================================================
--- libmicrohttpd/src/microhttpd/Makefile.am    2016-10-11 15:21:07 UTC (rev 
38113)
+++ libmicrohttpd/src/microhttpd/Makefile.am    2016-10-11 15:21:11 UTC (rev 
38114)
@@ -67,7 +67,7 @@
   mhd_threads.c mhd_threads.h \
   mhd_locks.h mhd_sem.c \
   mhd_sockets.c mhd_sockets.h \
-  mhd_itc.c mhd_itc.h \
+  mhd_itc.c mhd_itc.h mhd_itc_types.h \
   mhd_compat.h \
   response.c response.h
 if HAVE_W32

Modified: libmicrohttpd/src/microhttpd/connection.c
===================================================================
--- libmicrohttpd/src/microhttpd/connection.c   2016-10-11 15:21:07 UTC (rev 
38113)
+++ libmicrohttpd/src/microhttpd/connection.c   2016-10-11 15:21:11 UTC (rev 
38114)
@@ -34,6 +34,7 @@
 #include "mhd_locks.h"
 #include "mhd_sockets.h"
 #include "mhd_compat.h"
+#include "mhd_itc.h"
 
 
 /**
@@ -521,9 +522,7 @@
      to resume accepting connections */
   if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
        (! MHD_INVALID_PIPE_ (daemon->itc)) &&
-       (1 != MHD_pipe_write_ (daemon->itc,
-                              "c",
-                              1)) )
+       (! MHD_itc_activate_ (daemon->itc, "c")) )
     {
 #ifdef HAVE_MESSAGES
       MHD_DLOG (daemon,

Modified: libmicrohttpd/src/microhttpd/daemon.c
===================================================================
--- libmicrohttpd/src/microhttpd/daemon.c       2016-10-11 15:21:07 UTC (rev 
38113)
+++ libmicrohttpd/src/microhttpd/daemon.c       2016-10-11 15:21:11 UTC (rev 
38114)
@@ -2029,9 +2029,7 @@
   else
     if ( (MHD_YES == external_add) &&
         (! MHD_INVALID_PIPE_(daemon->itc)) &&
-        (1 != MHD_pipe_write_ (daemon->itc,
-                                "n",
-                                1)) )
+        (! MHD_itc_activate_ (daemon->itc, "n")) )
       {
 #ifdef HAVE_MESSAGES
        MHD_DLOG (daemon,
@@ -2212,7 +2210,7 @@
   connection->resuming = MHD_YES;
   daemon->resuming = MHD_YES;
   if ( (! MHD_INVALID_PIPE_(daemon->itc)) &&
-       (1 != MHD_pipe_write_ (daemon->itc, "r", 1)) )
+       (! MHD_itc_activate_ (daemon->itc, "r")) )
     {
 #ifdef HAVE_MESSAGES
       MHD_DLOG (daemon,
@@ -3792,9 +3790,7 @@
 #endif
         if (! MHD_INVALID_PIPE_(daemon->worker_pool[i].itc))
           {
-            if (1 != MHD_pipe_write_ (daemon->worker_pool[i].itc,
-                                      "q",
-                                      1))
+            if (! MHD_itc_activate_ (daemon->worker_pool[i].itc, "q"))
               MHD_PANIC (_("Failed to signal quiesce via pipe"));
           }
       }
@@ -3815,9 +3811,7 @@
 #endif
     if (! MHD_INVALID_PIPE_(daemon->itc))
     {
-      if (1 != MHD_pipe_write_ (daemon->itc,
-                                "q",
-                                1))
+      if (! MHD_itc_activate_ (daemon->itc, "q"))
        MHD_PANIC (_("failed to signal quiesce via pipe"));
     }
 
@@ -5186,7 +5180,7 @@
 #if MHD_WINSOCK_SOCKETS
       if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
            (! MHD_INVALID_PIPE_(daemon->itc)) &&
-           (1 != MHD_pipe_write_ (daemon->itc, "e", 1)) )
+           (! MHD_itc_activate_ (daemon->itc, "e")) )
         MHD_PANIC (_("Failed to signal shutdown via pipe"));
 #endif
     }
@@ -5289,7 +5283,7 @@
     }
   if (! MHD_INVALID_PIPE_(daemon->itc))
     {
-      if (1 != MHD_pipe_write_ (daemon->itc, "e", 1))
+      if (! MHD_itc_activate_ (daemon->itc, "e"))
        MHD_PANIC (_("Failed to signal shutdown via pipe"));
     }
 #ifdef HAVE_LISTEN_SHUTDOWN
@@ -5325,9 +5319,7 @@
        {
          if (! MHD_INVALID_PIPE_(daemon->worker_pool[i].itc))
            {
-             if (1 != MHD_pipe_write_ (daemon->worker_pool[i].itc,
-                                        "e",
-                                        1))
+             if (! MHD_itc_activate_ (daemon->worker_pool[i].itc, "e"))
                MHD_PANIC (_("Failed to signal shutdown via pipe."));
            }
          if (!MHD_join_thread_ (daemon->worker_pool[i].pid))

Modified: libmicrohttpd/src/microhttpd/internal.h
===================================================================
--- libmicrohttpd/src/microhttpd/internal.h     2016-10-11 15:21:07 UTC (rev 
38113)
+++ libmicrohttpd/src/microhttpd/internal.h     2016-10-11 15:21:11 UTC (rev 
38114)
@@ -62,7 +62,7 @@
 #include "mhd_threads.h"
 #include "mhd_locks.h"
 #include "mhd_sockets.h"
-#include "mhd_itc.h"
+#include "mhd_itc_types.h"
 
 
 /**

Modified: libmicrohttpd/src/microhttpd/mhd_itc.c
===================================================================
--- libmicrohttpd/src/microhttpd/mhd_itc.c      2016-10-11 15:21:07 UTC (rev 
38113)
+++ libmicrohttpd/src/microhttpd/mhd_itc.c      2016-10-11 15:21:11 UTC (rev 
38114)
@@ -33,24 +33,6 @@
 #include "internal.h"
 
 
-#ifdef _MHD_ITC_EVENTFD
-
-int
-MHD_pipe_write_ (MHD_itc_ pip,
-                 const void *ptr,
-                 size_t sz)
-{
-  uint64_t val = 1;
-  if (sizeof (val) !=
-      write (pip,
-             &val,
-             sizeof (val)))
-    MHD_PANIC (_("Failed to write to eventfd\n"));
-  return sz;
-}
-
-#endif /* _MHD_ITC_EVENTFD */
-
 #if defined(_MHD_ITC_PIPE)
 #if !defined(_WIN32) || defined(__CYGWIN__)
 

Modified: libmicrohttpd/src/microhttpd/mhd_itc.h
===================================================================
--- libmicrohttpd/src/microhttpd/mhd_itc.h      2016-10-11 15:21:07 UTC (rev 
38113)
+++ libmicrohttpd/src/microhttpd/mhd_itc.h      2016-10-11 15:21:11 UTC (rev 
38114)
@@ -32,27 +32,22 @@
  */
 #ifndef MHD_ITC_H
 #define MHD_ITC_H 1
-#include "mhd_options.h"
+#include "mhd_itc_types.h"
 
-/* Force socketpair on native W32 */
-#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(_MHD_ITC_SOCKETPAIR)
-#error _MHD_ITC_SOCKETPAIR is not defined on naitive W32 platform
-#endif /* _WIN32 && !__CYGWIN__ && !_MHD_ITC_SOCKETPAIR */
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
 #include <fcntl.h>
 
 #if defined(_MHD_ITC_EVENTFD)
-#include <sys/eventfd.h>
 
 /* **************** Optimized GNU/Linux ITC implementation by eventfd 
********** */
+#include <sys/eventfd.h>
+#include <stdint.h>      /* for uint64_t */
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>      /* for read(), write(), errno */
+#endif /* HAVE_UNISTD_H */
+#ifdef HAVE_STRING_H
+#include <string.h> /* for strerror() */
+#endif
 
-/**
- * Data type for a MHD ITC.
- */
-typedef int MHD_itc_;
 
 /**
  * Initialise ITC by generating eventFD
@@ -67,13 +62,19 @@
 #define MHD_itc_last_strerror_() strerror(errno)
 
 /**
- * write data to real pipe
+ * Internal static const helper for MHD_itc_activate_()
  */
-int
-MHD_pipe_write_ (MHD_itc_ pip,
-                 const void *ptr,
-                 size_t sz);
+static const uint64_t _MHD_itc_wr_data = 1;
 
+/**
+ * Activate signal on @a itc
+ * @param itc the itc to use
+ * @param str ignored
+ * @return non-zero if succeeded, zero otherwise
+ */
+#define MHD_itc_activate_(itc, str) \
+  ((write((itc), (const void*)&_MHD_itc_wr_data, 8) > 0) || (EAGAIN == errno))
+
 #define MHD_pipe_get_read_fd_(pip) (pip)
 
 #define MHD_pipe_get_write_fd_(pip) (pip)
@@ -122,18 +123,13 @@
 
 /* **************** Standard UNIX ITC implementation by pipe ********** */
 
-#  ifdef HAVE_STRING_H
-#    include <string.h> /* for strerror() */
-#  endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>      /* for read(), write(), errno */
+#endif /* HAVE_UNISTD_H */
+#ifdef HAVE_STRING_H
+#include <string.h> /* for strerror() */
+#endif
 
-/**
- * Data type for a MHD ITC.
- */
-struct MHD_Itc
-{
-  int fd[2];
-};
-typedef struct MHD_Itc MHD_itc_;
 
 /**
  * Initialise ITC by generating pipe
@@ -148,9 +144,13 @@
 #define MHD_itc_last_strerror_() strerror(errno)
 
 /**
- * write data to real pipe
+ * Activate signal on @a itc
+ * @param itc the itc to use
+ * @param str one-symbol string, useful only for strace debug
+ * @return non-zero if succeeded, zero otherwise
  */
-#define MHD_pipe_write_(pip, ptr, sz) write((pip).fd[1], (const void*)(ptr), 
(sz))
+#define MHD_itc_activate_(itc, str) \
+  ((write((itc).fd[1], (const void*)(str), 1) > 0) || (EAGAIN == errno))
 
 
 #define MHD_pipe_get_read_fd_(pip) ((pip).fd[0])
@@ -205,14 +205,6 @@
 
 #include "mhd_sockets.h"
 
-/**
- * Data type for a MHD pipe.
- */
-struct MHD_Itc
-{
-  MHD_socket sk[2];
-};
-typedef struct MHD_Itc MHD_itc_;
 
 /**
  * Initialise ITC by generating socketpair
@@ -227,9 +219,14 @@
 #define MHD_itc_last_strerror_() MHD_socket_last_strerr_()
 
 /**
- * Write data to emulated pipe
+ * Activate signal on @a itc
+ * @param itc the itc to use
+ * @param str one-symbol string, useful only for strace debug
+ * @return non-zero if succeeded, zero otherwise
  */
-#define MHD_pipe_write_(pip, ptr, sz) send((pip).sk[1], (const char*)(ptr), 
(sz), 0)
+#define MHD_itc_activate_(itc, str) \
+  ((send((itc).sk[1], (const char*)(str), 1, 0) > 0) || \
+   (MHD_SCKT_ERR_IS_EAGAIN_(MHD_socket_get_error_())))
 
 #define MHD_pipe_get_read_fd_(pip) ((pip).sk[0])
 

Added: libmicrohttpd/src/microhttpd/mhd_itc_types.h
===================================================================
--- libmicrohttpd/src/microhttpd/mhd_itc_types.h                                
(rev 0)
+++ libmicrohttpd/src/microhttpd/mhd_itc_types.h        2016-10-11 15:21:11 UTC 
(rev 38114)
@@ -0,0 +1,83 @@
+/*
+  This file is part of libmicrohttpd
+  Copyright (C) 2016 Karlson2k (Evgeny Grin), Christian Grothoff
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License as published by the Free Software Foundation; either
+  version 2.1 of the License, or (at your option) any later version.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  
USA
+
+*/
+
+/**
+ * @file microhttpd/mhd_itc_types.h
+ * @brief  Types for platform-independent inter-thread communication
+ * @author Karlson2k (Evgeny Grin)
+ * @author Christian Grothoff
+ *
+ * Provides basic types for inter-thread communication.
+ * Designed to be included by other headers.
+ */
+#ifndef MHD_ITC_TYPES_H
+#define MHD_ITC_TYPES_H 1
+#include "mhd_options.h"
+
+/* Force socketpair on native W32 */
+#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(_MHD_ITC_SOCKETPAIR)
+#error _MHD_ITC_SOCKETPAIR is not defined on naitive W32 platform
+#endif /* _WIN32 && !__CYGWIN__ && !_MHD_ITC_SOCKETPAIR */
+
+#if defined(_MHD_ITC_EVENTFD)
+/* **************** Optimized GNU/Linux ITC implementation by eventfd 
********** */
+
+/**
+ * Data type for a MHD ITC.
+ */
+typedef int MHD_itc_;
+
+#elif defined(_MHD_ITC_PIPE)
+/* **************** Standard UNIX ITC implementation by pipe ********** */
+
+/**
+ * Base data type for a MHD ITC.
+ */
+struct MHD_Itc
+{
+  int fd[2];
+};
+
+/**
+ * Data type for a MHD ITC.
+ */
+typedef struct MHD_Itc MHD_itc_;
+
+#elif defined(_MHD_ITC_SOCKETPAIR)
+/* **************** ITC implementation by socket pair ********** */
+
+#include "mhd_sockets.h"
+
+/**
+ * Base data type for a MHD ITC.
+ */
+struct MHD_Itc
+{
+  MHD_socket sk[2];
+};
+
+/**
+ * Data type for a MHD ITC.
+ */
+typedef struct MHD_Itc MHD_itc_;
+
+#endif /* _MHD_ITC_SOCKETPAIR */
+
+#endif /* ! MHD_ITC_TYPES_H */

Modified: libmicrohttpd/w32/common/libmicrohttpd-files.vcxproj
===================================================================
--- libmicrohttpd/w32/common/libmicrohttpd-files.vcxproj        2016-10-11 
15:21:07 UTC (rev 38113)
+++ libmicrohttpd/w32/common/libmicrohttpd-files.vcxproj        2016-10-11 
15:21:11 UTC (rev 38114)
@@ -42,6 +42,7 @@
     <ClInclude Include="$(MhdSrc)microhttpd\mhd_locks.h" />
     <ClInclude Include="$(MhdSrc)microhttpd\mhd_sockets.h" />
     <ClInclude Include="$(MhdSrc)microhttpd\mhd_itc.h" />
+    <ClInclude Include="$(MhdSrc)microhttpd\mhd_itc_types.h" />
     <ClInclude Include="$(MhdSrc)microhttpd\mhd_compat.h" />
     <ClInclude Include="$(MhdW32Common)MHD_config.h" />
   </ItemGroup>

Modified: libmicrohttpd/w32/common/libmicrohttpd-filters.vcxproj
===================================================================
--- libmicrohttpd/w32/common/libmicrohttpd-filters.vcxproj      2016-10-11 
15:21:07 UTC (rev 38113)
+++ libmicrohttpd/w32/common/libmicrohttpd-filters.vcxproj      2016-10-11 
15:21:11 UTC (rev 38114)
@@ -132,6 +132,9 @@
     <ClCompile Include="$(MhdSrc)microhttpd\mhd_sockets.c">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClInclude Include="$(MhdSrc)microhttpd\mhd_itc_types.h">
+      <Filter>Source Files</Filter>
+    </ClInclude>
     <ClInclude Include="$(MhdSrc)microhttpd\mhd_itc.h">
       <Filter>Source Files</Filter>
     </ClInclude>




reply via email to

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