From: Andy Pan Date: Wed, 5 Jun 2024 08:08:15 +0000 (+0800) Subject: socketpair: provide `Curl_socketpair` only when `!CURL_DISABLE_SOCKETPAIR` X-Git-Tag: curl-8_9_0~281 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f786fce914f774ff8176cc2951e405bd29f1bdc3;p=thirdparty%2Fcurl.git socketpair: provide `Curl_socketpair` only when `!CURL_DISABLE_SOCKETPAIR` Ref: https://curl.se/dev/log.cgi?id=20240605035856-3529577 Reported-by: Marcel Raad Closes #13888 --- diff --git a/lib/socketpair.c b/lib/socketpair.c index 284433d5a1..3b9e406993 100644 --- a/lib/socketpair.c +++ b/lib/socketpair.c @@ -75,7 +75,29 @@ int Curl_pipe(curl_socket_t socks[2], bool nonblocking) #endif -#if !defined(HAVE_SOCKETPAIR) && !defined(CURL_DISABLE_SOCKETPAIR) +#ifndef CURL_DISABLE_SOCKETPAIR +#ifdef HAVE_SOCKETPAIR +int Curl_socketpair(int domain, int type, int protocol, + curl_socket_t socks[2], bool nonblocking) +{ +#ifdef SOCK_NONBLOCK + type = nonblocking ? type | SOCK_NONBLOCK : type; +#endif + if(socketpair(domain, type, protocol, socks)) + return -1; +#ifndef SOCK_NONBLOCK + if(nonblocking) { + if(curlx_nonblock(socks[0], TRUE) < 0 || + curlx_nonblock(socks[1], TRUE) < 0) { + close(socks[0]); + close(socks[1]); + return -1; + } + } +#endif + return 0; +} +#else /* !HAVE_SOCKETPAIR */ #ifdef _WIN32 /* * This is a socketpair() implementation for Windows. @@ -238,25 +260,5 @@ error: sclose(socks[1]); return -1; } -#else -int Curl_socketpair(int domain, int type, int protocol, - curl_socket_t socks[2], bool nonblocking) -{ -#ifdef SOCK_NONBLOCK - type = nonblocking ? type | SOCK_NONBLOCK : type; -#endif - if(socketpair(domain, type, protocol, socks)) - return -1; -#ifndef SOCK_NONBLOCK - if(nonblocking) { - if(curlx_nonblock(socks[0], TRUE) < 0 || - curlx_nonblock(socks[1], TRUE) < 0) { - close(socks[0]); - close(socks[1]); - return -1; - } - } #endif - return 0; -} -#endif /* ! HAVE_SOCKETPAIR */ +#endif /* !CURL_DISABLE_SOCKETPAIR */ diff --git a/lib/socketpair.h b/lib/socketpair.h index 5f9c7613ce..42f4034fc5 100644 --- a/lib/socketpair.h +++ b/lib/socketpair.h @@ -63,7 +63,7 @@ int Curl_eventfd(curl_socket_t socks[2], bool nonblocking); #include 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 @@ -86,10 +86,13 @@ int Curl_pipe(curl_socket_t socks[2], bool nonblocking); #define wakeup_create(p,nb)\ Curl_socketpair(SOCKETPAIR_FAMILY, SOCKETPAIR_TYPE, 0, p, nb) -#endif /* HAVE_PIPE */ +#endif /* USE_EVENTFD */ +#ifndef CURL_DISABLE_SOCKETPAIR #include int Curl_socketpair(int domain, int type, int protocol, curl_socket_t socks[2], bool nonblocking); +#endif + #endif /* HEADER_CURL_SOCKETPAIR_H */