45# define MHD_PANIC(msg) do { fprintf (stderr, \
46 "Abnormal termination at %d line in file %s: %s\n", \
47 (int) __LINE__, __FILE__, msg); abort (); \
51#if defined(_MHD_ITC_EVENTFD)
54#include <sys/eventfd.h>
69#define MHD_itc_init_(itc) (-1 != ((itc).fd = eventfd (0, EFD_CLOEXEC \
75#define MHD_itc_last_strerror_() strerror (errno)
80static const uint64_t _MHD_itc_wr_data = 1;
88#define MHD_itc_activate_(itc, str) \
89 ((write ((itc).fd, (const void*) &_MHD_itc_wr_data, 8) > 0) || (EAGAIN == \
97#define MHD_itc_r_fd_(itc) ((itc).fd)
104#define MHD_itc_w_fd_(itc) ((itc).fd)
110#define MHD_itc_clear_(itc) \
111 do { uint64_t __b; int __r; \
112 __r = read ((itc).fd, &__b, sizeof(__b)); \
113 (void) __r; } while (0)
122#define MHD_itc_destroy_(itc) ((0 == close ((itc).fd)) || (EBADF != errno))
133#define MHD_ITC_IS_VALID_(itc) (-1 != ((itc).fd))
139#define MHD_itc_set_invalid_(itc) ((itc).fd = -1)
142#elif defined(_MHD_ITC_PIPE)
146#if defined(HAVE_PIPE2_FUNC) && defined(HAVE_FCNTL_H)
162#ifdef HAVE_PIPE2_FUNC
163# define MHD_itc_init_(itc) (! pipe2 ((itc).fd, O_CLOEXEC | O_NONBLOCK))
165# define MHD_itc_init_(itc) \
166 ( (! pipe ((itc).fd)) ? \
167 (MHD_itc_nonblocking_ ((itc)) ? \
169 (MHD_itc_destroy_ ((itc)), 0) ) \
176#define MHD_itc_last_strerror_() strerror (errno)
184#define MHD_itc_activate_(itc, str) \
185 ((write ((itc).fd[1], (const void*) (str), 1) > 0) || (EAGAIN == errno))
193#define MHD_itc_r_fd_(itc) ((itc).fd[0])
200#define MHD_itc_w_fd_(itc) ((itc).fd[1])
206#define MHD_itc_clear_(itc) do \
208 while (0 < read ((itc).fd[0], &__b, sizeof(__b))) \
216#define MHD_itc_destroy_(itc) \
217 ( (0 == close ((itc).fd[0])) ? \
218 (0 == close ((itc).fd[1])) : \
219 ((close ((itc).fd[1])), 0) )
230#define MHD_ITC_IS_VALID_(itc) (-1 != (itc).fd[0])
236#define MHD_itc_set_invalid_(itc) ((itc).fd[0] = (itc).fd[1] = -1)
238#ifndef HAVE_PIPE2_FUNC
246MHD_itc_nonblocking_ (
struct MHD_itc_ itc);
251#elif defined(_MHD_ITC_SOCKETPAIR)
255#include "mhd_sockets.h"
263#ifdef MHD_socket_pair_nblk_
264# define MHD_itc_init_(itc) MHD_socket_pair_nblk_ ((itc).sk)
266# define MHD_itc_init_(itc) \
267 (MHD_socket_pair_ ((itc).sk) ? \
268 (MHD_itc_nonblocking_ ((itc)) ? \
270 (MHD_itc_destroy_ ((itc)), 0) ) \
277#define MHD_itc_last_strerror_() MHD_socket_last_strerr_ ()
285#define MHD_itc_activate_(itc, str) \
286 ((MHD_send_ ((itc).sk[1], (str), 1) > 0) || \
287 (MHD_SCKT_ERR_IS_EAGAIN_ (MHD_socket_get_error_ ())))
294#define MHD_itc_r_fd_(itc) ((itc).sk[0])
301#define MHD_itc_w_fd_(itc) ((itc).sk[1])
307#define MHD_itc_clear_(itc) do \
309 while (0 < recv ((itc).sk[0], \
319#define MHD_itc_destroy_(itc) \
320 (MHD_socket_close_ ((itc).sk[0]) ? \
321 MHD_socket_close_ ((itc).sk[1]) : \
322 ((void) MHD_socket_close_ ((itc).sk[1]), 0) )
334#define MHD_ITC_IS_VALID_(itc) (MHD_INVALID_SOCKET != (itc).sk[0])
340#define MHD_itc_set_invalid_(itc) ((itc).sk[0] = (itc).sk[1] = \
343#ifndef MHD_socket_pair_nblk_
344# define MHD_itc_nonblocking_(pip) (MHD_socket_nonblocking_ ((pip).sk[0]) && \
345 MHD_socket_nonblocking_ ((pip).sk[1]))
355#define MHD_itc_destroy_chk_(itc) do { \
356 if (! MHD_itc_destroy_ (itc)) \
357 MHD_PANIC (_ ("Failed to destroy ITC.\n")); \
369#define MHD_ITC_IS_INVALID_(itc) (! MHD_ITC_IS_VALID_ (itc))
Types for platform-independent inter-thread communication.