43# define MHD_PANIC(msg) do { fprintf (stderr, \
44 "Abnormal termination at %d line in file %s: %s\n", \
45 (int) __LINE__, __FILE__, msg); abort (); \
49#if defined(_MHD_ITC_EVENTFD)
52#include <sys/eventfd.h>
67#define MHD_itc_init_(itc) (-1 != ((itc).fd = eventfd (0, EFD_CLOEXEC \
73#define MHD_itc_last_strerror_() strerror (errno)
78static const uint64_t _MHD_itc_wr_data = 1;
86#define MHD_itc_activate_(itc, str) \
87 ((write ((itc).fd, (const void*) &_MHD_itc_wr_data, 8) > 0) || (EAGAIN == \
95#define MHD_itc_r_fd_(itc) ((itc).fd)
102#define MHD_itc_w_fd_(itc) ((itc).fd)
108#define MHD_itc_clear_(itc) \
109 do { uint64_t __b; int __r; \
110 __r = read ((itc).fd, &__b, sizeof(__b)); \
111 (void) __r; } while (0)
120#define MHD_itc_destroy_(itc) ((0 == close ((itc).fd)) || (EBADF != errno))
131#define MHD_ITC_IS_VALID_(itc) (-1 != ((itc).fd))
137#define MHD_itc_set_invalid_(itc) ((itc).fd = -1)
140#elif defined(_MHD_ITC_PIPE)
144#if defined(HAVE_PIPE2_FUNC) && defined(HAVE_FCNTL_H)
160#ifdef HAVE_PIPE2_FUNC
161# define MHD_itc_init_(itc) (! pipe2 ((itc).fd, O_CLOEXEC | O_NONBLOCK))
163# define MHD_itc_init_(itc) \
164 ( (! pipe ((itc).fd)) ? \
165 (MHD_itc_nonblocking_ ((itc)) ? \
167 (MHD_itc_destroy_ ((itc)), 0) ) \
174#define MHD_itc_last_strerror_() strerror (errno)
182#define MHD_itc_activate_(itc, str) \
183 ((write ((itc).fd[1], (const void*) (str), 1) > 0) || (EAGAIN == errno))
191#define MHD_itc_r_fd_(itc) ((itc).fd[0])
198#define MHD_itc_w_fd_(itc) ((itc).fd[1])
204#define MHD_itc_clear_(itc) do \
206 while (0 < read ((itc).fd[0], &__b, sizeof(__b))) \
214#define MHD_itc_destroy_(itc) \
215 ( (0 == close ((itc).fd[0])) ? \
216 (0 == close ((itc).fd[1])) : \
217 ((close ((itc).fd[1])), 0) )
228#define MHD_ITC_IS_VALID_(itc) (-1 != (itc).fd[0])
234#define MHD_itc_set_invalid_(itc) ((itc).fd[0] = (itc).fd[1] = -1)
236#ifndef HAVE_PIPE2_FUNC
244MHD_itc_nonblocking_ (
struct MHD_itc_ itc);
249#elif defined(_MHD_ITC_SOCKETPAIR)
253#include "mhd_sockets.h"
261#ifdef MHD_socket_pair_nblk_
262# define MHD_itc_init_(itc) MHD_socket_pair_nblk_ ((itc).sk)
264# define MHD_itc_init_(itc) \
265 (MHD_socket_pair_ ((itc).sk) ? \
266 (MHD_itc_nonblocking_ ((itc)) ? \
268 (MHD_itc_destroy_ ((itc)), 0) ) \
275#define MHD_itc_last_strerror_() MHD_socket_last_strerr_ ()
283#define MHD_itc_activate_(itc, str) \
284 ((MHD_send_ ((itc).sk[1], (str), 1) > 0) || \
285 (MHD_SCKT_ERR_IS_EAGAIN_ (MHD_socket_get_error_ ())))
292#define MHD_itc_r_fd_(itc) ((itc).sk[0])
299#define MHD_itc_w_fd_(itc) ((itc).sk[1])
305#define MHD_itc_clear_(itc) do \
307 while (0 < recv ((itc).sk[0], \
317#define MHD_itc_destroy_(itc) \
318 (MHD_socket_close_ ((itc).sk[0]) ? \
319 MHD_socket_close_ ((itc).sk[1]) : \
320 ((void) MHD_socket_close_ ((itc).sk[1]), 0) )
332#define MHD_ITC_IS_VALID_(itc) (MHD_INVALID_SOCKET != (itc).sk[0])
338#define MHD_itc_set_invalid_(itc) ((itc).sk[0] = (itc).sk[1] = \
341#ifndef MHD_socket_pair_nblk_
342# define MHD_itc_nonblocking_(pip) (MHD_socket_nonblocking_ ((pip).sk[0]) && \
343 MHD_socket_nonblocking_ ((pip).sk[1]))
353#define MHD_itc_destroy_chk_(itc) do { \
354 if (! MHD_itc_destroy_ (itc)) \
355 MHD_PANIC (_ ("Failed to destroy ITC.\n")); \
367#define MHD_ITC_IS_INVALID_(itc) (! MHD_ITC_IS_VALID_ (itc))
Types for platform-independent inter-thread communication.