2
0

socketpair.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. #include "curl_setup.h"
  27. #if defined(HAVE_EVENTFD) && \
  28. defined(__x86_64__) && \
  29. defined(__aarch64__) && \
  30. defined(__ia64__) && \
  31. defined(__ppc64__) && \
  32. defined(__mips64) && \
  33. defined(__sparc64__) && \
  34. defined(__riscv_64e) && \
  35. defined(__s390x__)
  36. /* Use eventfd only with 64-bit CPU architectures because eventfd has a
  37. * stringent rule of requiring the 8-byte buffer when calling read(2) and
  38. * write(2) on it. In some rare cases, the C standard library implementation
  39. * on a 32-bit system might choose to define uint64_t as a 32-bit type for
  40. * various reasons (memory limitations, compatibility with older code),
  41. * which makes eventfd broken.
  42. */
  43. #define USE_EVENTFD 1
  44. #define wakeup_write write
  45. #define wakeup_read read
  46. #define wakeup_close close
  47. #define wakeup_create(p,nb) Curl_eventfd(p,nb)
  48. #include <curl/curl.h>
  49. int Curl_eventfd(curl_socket_t socks[2], bool nonblocking);
  50. #elif defined(HAVE_PIPE)
  51. #define wakeup_write write
  52. #define wakeup_read read
  53. #define wakeup_close close
  54. #define wakeup_create(p,nb) Curl_pipe(p,nb)
  55. #include <curl/curl.h>
  56. int Curl_pipe(curl_socket_t socks[2], bool nonblocking);
  57. #else /* !USE_EVENTFD && !HAVE_PIPE */
  58. #define wakeup_write swrite
  59. #define wakeup_read sread
  60. #define wakeup_close sclose
  61. #if defined(USE_UNIX_SOCKETS) && defined(HAVE_SOCKETPAIR)
  62. #define SOCKETPAIR_FAMILY AF_UNIX
  63. #elif !defined(HAVE_SOCKETPAIR)
  64. #define SOCKETPAIR_FAMILY 0 /* not used */
  65. #else
  66. #error "unsupported unix domain and socketpair build combo"
  67. #endif
  68. #ifdef SOCK_CLOEXEC
  69. #define SOCKETPAIR_TYPE (SOCK_STREAM | SOCK_CLOEXEC)
  70. #else
  71. #define SOCKETPAIR_TYPE SOCK_STREAM
  72. #endif
  73. #define wakeup_create(p,nb)\
  74. Curl_socketpair(SOCKETPAIR_FAMILY, SOCKETPAIR_TYPE, 0, p, nb)
  75. #endif /* USE_EVENTFD */
  76. #ifndef CURL_DISABLE_SOCKETPAIR
  77. #include <curl/curl.h>
  78. int Curl_socketpair(int domain, int type, int protocol,
  79. curl_socket_t socks[2], bool nonblocking);
  80. #endif
  81. #endif /* HEADER_CURL_SOCKETPAIR_H */