1 #ifndef HEADER_CURL_SOCKETPAIR_H 2 #define HEADER_CURL_SOCKETPAIR_H 3 /*************************************************************************** 4 * _ _ ____ _ 5 * Project ___| | | | _ \| | 6 * / __| | | | |_) | | 7 * | (__| |_| | _ <| |___ 8 * \___|\___/|_| \_\_____| 9 * 10 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 11 * 12 * This software is licensed as described in the file COPYING, which 13 * you should have received as part of this distribution. The terms 14 * are also available at https://curl.se/docs/copyright.html. 15 * 16 * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 * copies of the Software, and permit persons to whom the Software is 18 * furnished to do so, under the terms of the COPYING file. 19 * 20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 * KIND, either express or implied. 22 * 23 * SPDX-License-Identifier: curl 24 * 25 ***************************************************************************/ 26 27 #include "curl_setup.h" 28 29 #if defined(HAVE_EVENTFD) && \ 30 (defined(__x86_64__) || \ 31 defined(__aarch64__) || \ 32 defined(__ia64__) || \ 33 defined(__ppc64__) || \ 34 defined(__mips64) || \ 35 defined(__sparc64__) || \ 36 defined(__riscv_64e) || \ 37 defined(__s390x__)) 38 39 /* Use eventfd only with 64-bit CPU architectures because eventfd has a 40 * stringent rule of requiring the 8-byte buffer when calling read(2) and 41 * write(2) on it. In some rare cases, the C standard library implementation 42 * on a 32-bit system might choose to define uint64_t as a 32-bit type for 43 * various reasons (memory limitations, compatibility with older code), 44 * which makes eventfd broken. 45 */ 46 #define USE_EVENTFD 1 47 48 #define wakeup_write write 49 #define wakeup_read read 50 #define wakeup_close close 51 #define wakeup_create(p,nb) Curl_eventfd(p,nb) 52 53 #include <curl/curl.h> 54 int Curl_eventfd(curl_socket_t socks[2], bool nonblocking); 55 56 #elif defined(HAVE_PIPE) 57 58 #define wakeup_write write 59 #define wakeup_read read 60 #define wakeup_close close 61 #define wakeup_create(p,nb) Curl_pipe(p,nb) 62 63 #include <curl/curl.h> 64 int Curl_pipe(curl_socket_t socks[2], bool nonblocking); 65 66 #else /* !USE_EVENTFD && !HAVE_PIPE */ 67 68 #define wakeup_write swrite 69 #define wakeup_read sread 70 #define wakeup_close sclose 71 72 #if defined(USE_UNIX_SOCKETS) && defined(HAVE_SOCKETPAIR) 73 #define SOCKETPAIR_FAMILY AF_UNIX 74 #elif !defined(HAVE_SOCKETPAIR) 75 #define SOCKETPAIR_FAMILY 0 /* not used */ 76 #else 77 #error "unsupported Unix domain and socketpair build combo" 78 #endif 79 80 #ifdef SOCK_CLOEXEC 81 #define SOCKETPAIR_TYPE (SOCK_STREAM | SOCK_CLOEXEC) 82 #else 83 #define SOCKETPAIR_TYPE SOCK_STREAM 84 #endif 85 86 #define wakeup_create(p,nb)\ 87 Curl_socketpair(SOCKETPAIR_FAMILY, SOCKETPAIR_TYPE, 0, p, nb) 88 89 #endif /* USE_EVENTFD */ 90 91 #ifndef CURL_DISABLE_SOCKETPAIR 92 #include <curl/curl.h> 93 94 int Curl_socketpair(int domain, int type, int protocol, 95 curl_socket_t socks[2], bool nonblocking); 96 #endif 97 98 #endif /* HEADER_CURL_SOCKETPAIR_H */ 99