summaryrefslogtreecommitdiff
path: root/libs/libcurl/src/socketpair.h
diff options
context:
space:
mode:
Diffstat (limited to 'libs/libcurl/src/socketpair.h')
-rw-r--r--libs/libcurl/src/socketpair.h52
1 files changed, 36 insertions, 16 deletions
diff --git a/libs/libcurl/src/socketpair.h b/libs/libcurl/src/socketpair.h
index b52b8b7d8a..38d8245bc4 100644
--- a/libs/libcurl/src/socketpair.h
+++ b/libs/libcurl/src/socketpair.h
@@ -26,21 +26,44 @@
#include "curl_setup.h"
-#ifdef HAVE_PIPE
+#if defined(HAVE_EVENTFD) && \
+ defined(__x86_64__) && \
+ defined(__aarch64__) && \
+ defined(__ia64__) && \
+ defined(__ppc64__) && \
+ defined(__mips64) && \
+ defined(__sparc64__) && \
+ defined(__riscv_64e) && \
+ defined(__s390x__)
+
+/* Use eventfd only with 64-bit CPU architectures because eventfd has a
+ * stringent rule of requiring the 8-byte buffer when calling read(2) and
+ * write(2) on it. In some rare cases, the C standard library implementation
+ * on a 32-bit system might choose to define uint64_t as a 32-bit type for
+ * various reasons (memory limitations, compatibility with older code),
+ * which makes eventfd broken.
+ */
+#define USE_EVENTFD 1
#define wakeup_write write
#define wakeup_read read
#define wakeup_close close
-#define wakeup_create(p) Curl_pipe(p)
+#define wakeup_create(p,nb) Curl_eventfd(p,nb)
-#ifdef HAVE_FCNTL
#include <curl/curl.h>
-int Curl_pipe(curl_socket_t socks[2]);
-#else
-#define Curl_pipe(p) pipe(p)
-#endif
+int Curl_eventfd(curl_socket_t socks[2], bool nonblocking);
+
+#elif defined(HAVE_PIPE)
+
+#define wakeup_write write
+#define wakeup_read read
+#define wakeup_close close
+#define wakeup_create(p,nb) Curl_pipe(p,nb)
+
+#include <curl/curl.h>
+int Curl_pipe(curl_socket_t socks[2], bool nonblocking);
-#else /* HAVE_PIPE */
+#else /* !USE_EVENTFD && !HAVE_PIPE */
#define wakeup_write swrite
#define wakeup_read sread
@@ -60,19 +83,16 @@ int Curl_pipe(curl_socket_t socks[2]);
#define SOCKETPAIR_TYPE SOCK_STREAM
#endif
-#define wakeup_create(p)\
-Curl_socketpair(SOCKETPAIR_FAMILY, SOCKETPAIR_TYPE, 0, p)
-
-#endif /* HAVE_PIPE */
+#define wakeup_create(p,nb)\
+Curl_socketpair(SOCKETPAIR_FAMILY, SOCKETPAIR_TYPE, 0, p, nb)
+#endif /* USE_EVENTFD */
-#ifndef HAVE_SOCKETPAIR
+#ifndef CURL_DISABLE_SOCKETPAIR
#include <curl/curl.h>
int Curl_socketpair(int domain, int type, int protocol,
- curl_socket_t socks[2]);
-#else
-#define Curl_socketpair(a,b,c,d) socketpair(a,b,c,d)
+ curl_socket_t socks[2], bool nonblocking);
#endif
#endif /* HEADER_CURL_SOCKETPAIR_H */