commit 21ffb5e8420d6b4284932ae0eb6021f2118e21be
parent b6ae5bf9b70c867664daced6f24b6ba28ebc6c82
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date: Tue, 11 Oct 2016 15:20:53 +0000
Renamed "pipe" to "itc" as it actually more some kind of channel, not always pipe.
Used typedef for "itc" type.
Diffstat:
3 files changed, 35 insertions(+), 45 deletions(-)
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
@@ -1352,13 +1352,9 @@ struct MHD_Daemon
#endif
/**
- * Pipe we use to signal shutdown, unless
- * 'HAVE_LISTEN_SHUTDOWN' is defined AND we have a listen
- * socket (which we can then 'shutdown' to stop listening).
- * MHD can be build with usage of socketpair instead of
- * pipe (forced on W32).
+ * Inter-thread communication channel.
*/
- struct MHD_Pipe wpipe;
+ MHD_itc_ wpipe;
/**
* Are we shutting down?
diff --git a/src/microhttpd/mhd_itc.c b/src/microhttpd/mhd_itc.c
@@ -36,13 +36,13 @@
#ifdef _MHD_ITC_EVENTFD
int
-MHD_pipe_write_ (struct MHD_Pipe pip,
+MHD_pipe_write_ (MHD_itc_ pip,
const void *ptr,
size_t sz)
{
uint64_t val = 1;
if (sizeof (val) !=
- write (pip.event_fd,
+ write (pip,
&val,
sizeof (val)))
MHD_PANIC (_("Failed to write to eventfd\n"));
@@ -62,7 +62,7 @@ MHD_pipe_write_ (struct MHD_Pipe pip,
* @return non-zero if succeeded, zero otherwise
*/
int
-MHD_itc_nonblocking_ (struct MHD_Pipe pip)
+MHD_itc_nonblocking_ (MHD_itc_ itc)
{
unsigned int i;
@@ -70,7 +70,7 @@ MHD_itc_nonblocking_ (struct MHD_Pipe pip)
{
int flags;
- flags = fcntl (pip.fd[i],
+ flags = fcntl (itc.fd[i],
F_GETFL);
if (-1 == flags)
return 0;
diff --git a/src/microhttpd/mhd_itc.h b/src/microhttpd/mhd_itc.h
@@ -20,7 +20,7 @@
/**
* @file microhttpd/mhd_itc.h
- * @brief Header for platform-independent inter-thread signaling via pipes
+ * @brief Header for platform-independent inter-thread communication
* @author Karlson2k (Evgeny Grin)
* @author Christian Grothoff
*
@@ -47,20 +47,17 @@
#if defined(_MHD_ITC_EVENTFD)
#include <sys/eventfd.h>
-/* **************** Optimized eventfd PIPE implementation ********** */
+/* **************** Optimized GNU/Linux ITC implementation by eventfd ********** */
/**
- * Data type for a MHD pipe.
+ * Data type for a MHD ITC.
*/
-struct MHD_Pipe
-{
- int event_fd;
-};
+typedef int MHD_itc_;
/**
* create pipe
*/
-#define MHD_pipe_(pip) ((-1 == (pip.event_fd = eventfd (0, EFD_CLOEXEC | EFD_NONBLOCK))) ? 0 : !0)
+#define MHD_pipe_(itc) ((-1 == (itc = eventfd (0, EFD_CLOEXEC | EFD_NONBLOCK))) ? 0 : !0)
/***
* Get description string of last errno for pipe operations.
@@ -71,27 +68,27 @@ struct MHD_Pipe
* write data to real pipe
*/
int
-MHD_pipe_write_ (struct MHD_Pipe pip,
+MHD_pipe_write_ (MHD_itc_ pip,
const void *ptr,
size_t sz);
-#define MHD_pipe_get_read_fd_(pip) (pip.event_fd)
+#define MHD_pipe_get_read_fd_(pip) (pip)
-#define MHD_pipe_get_write_fd_(pip) (pip.event_fd)
+#define MHD_pipe_get_write_fd_(pip) (pip)
/**
* drain data from real pipe
*/
#define MHD_pipe_drain_(pip) do { \
uint64_t tmp; \
- read (pip.event_fd, &tmp, sizeof (tmp)); \
+ read (pip, &tmp, sizeof (tmp)); \
} while (0)
/**
* Close any FDs of the pipe (non-W32)
*/
#define MHD_pipe_close_(pip) do { \
- if ( (0 != close (pip.event_fd)) && \
+ if ( (0 != close (pip)) && \
(EBADF == errno) ) \
MHD_PANIC (_("close failed")); \
} while (0)
@@ -99,13 +96,13 @@ MHD_pipe_write_ (struct MHD_Pipe pip,
/**
* Check if we have an uninitialized pipe
*/
-#define MHD_INVALID_PIPE_(pip) (-1 == pip.event_fd)
+#define MHD_INVALID_PIPE_(pip) (-1 == pip)
/**
* Setup uninitialized @a pip data structure.
*/
#define MHD_make_invalid_pipe_(pip) do { \
- pip.event_fd = -1; \
+ pip = -1; \
} while (0)
@@ -121,24 +118,25 @@ MHD_pipe_write_ (struct MHD_Pipe pip,
#elif defined(_MHD_ITC_PIPE)
-/* **************** STANDARD UNIX PIPE implementation ********** */
+/* **************** Standard UNIX ITC implementation by pipe ********** */
# ifdef HAVE_STRING_H
# include <string.h> /* for strerror() */
# endif
/**
- * Data type for a MHD pipe.
+ * Data type for a MHD ITC.
*/
-struct MHD_Pipe
+struct MHD_Itc
{
int fd[2];
};
+typedef struct MHD_Itc MHD_itc_;
/**
* create pipe
*/
-#define MHD_pipe_(pip) (!pipe((pip.fd)))
+#define MHD_pipe_(pip) (!pipe((pip).fd))
/***
* Get description string of last errno for pipe operations.
@@ -148,29 +146,29 @@ struct MHD_Pipe
/**
* write data to real pipe
*/
-#define MHD_pipe_write_(pip, ptr, sz) write((pip.fd[1]), (const void*)(ptr), (sz))
+#define MHD_pipe_write_(pip, ptr, sz) write((pip).fd[1], (const void*)(ptr), (sz))
-#define MHD_pipe_get_read_fd_(pip) (pip.fd[0])
+#define MHD_pipe_get_read_fd_(pip) ((pip).fd[0])
-#define MHD_pipe_get_write_fd_(pip) (pip.fd[1])
+#define MHD_pipe_get_write_fd_(pip) ((pip).fd[1])
/**
* drain data from real pipe
*/
#define MHD_pipe_drain_(pip) do { \
long tmp; \
- while (0 < read((pip.fd[0]), (void*)&tmp, sizeof (tmp))) ; \
+ while (0 < read((pip).fd[0], (void*)&tmp, sizeof (tmp))) ; \
} while (0)
/**
* Close any FDs of the pipe (non-W32)
*/
#define MHD_pipe_close_(pip) do { \
- if ( (0 != close (pip.fd[0])) && \
+ if ( (0 != close ((pip).fd[0])) && \
(EBADF == errno) ) \
MHD_PANIC (_("close failed")); \
- if ( (0 != close (pip.fd[1])) && \
+ if ( (0 != close ((pip).fd[1])) && \
(EBADF == errno) ) \
MHD_PANIC (_("close failed")); \
} while (0)
@@ -178,13 +176,13 @@ struct MHD_Pipe
/**
* Check if we have an uninitialized pipe
*/
-#define MHD_INVALID_PIPE_(pip) (-1 == pip.fd[0])
+#define MHD_INVALID_PIPE_(pip) (-1 == (pip).fd[0])
/**
* Setup uninitialized @a pip data structure.
*/
#define MHD_make_invalid_pipe_(pip) do { \
- pip.fd[0] = pip.fd[1] = -1; \
+ (pip).fd[0] = (pip).fd[1] = -1; \
} while (0)
/**
@@ -194,25 +192,23 @@ struct MHD_Pipe
* @return non-zero if succeeded, zero otherwise
*/
int
-MHD_itc_nonblocking_ (struct MHD_Pipe fd);
-
+MHD_itc_nonblocking_ (MHD_itc_ itc);
-/* **************** END OF STANDARD UNIX PIPE implementation ********** */
#elif defined(_MHD_ITC_SOCKETPAIR)
-/* **************** PIPE EMULATION by socket pairs ********** */
+/* **************** ITC implementation by socket pair ********** */
#include "mhd_sockets.h"
/**
* Data type for a MHD pipe.
*/
-struct MHD_Pipe
+struct MHD_Itc
{
MHD_socket fd[2];
};
-
+typedef struct MHD_Itc MHD_itc_;
/**
* Create two connected sockets to emulate a pipe.
@@ -262,8 +258,6 @@ struct MHD_Pipe
#define MHD_itc_nonblocking_(pip) (MHD_socket_nonblocking_((pip.fd[0])) && MHD_socket_nonblocking_((pip.fd[1])))
-/* **************** END OF PIPE EMULATION by socket pairs ********** */
-
#endif /* _MHD_ITC_SOCKETPAIR */
#endif /* MHD_ITC_H */