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
This commit is contained in:
Andy Pan 2024-06-05 16:08:15 +08:00 committed by Daniel Stenberg
parent 4e71f134e5
commit f786fce914
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
2 changed files with 29 additions and 24 deletions

View file

@ -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 */