socketpair: support pipe2 where available

By replacing pipe with pipe2, it would save us 4 extra system calls of
setting O_NONBLOCK and O_CLOEXEC. This system call is widely supported
across UNIX-like OS's: Linux, *BSD, and SunOS derivatives - Solaris,
illumos, etc.

Ref:
https://man7.org/linux/man-pages/man2/pipe.2.html
https://man.freebsd.org/cgi/man.cgi?query=pipe
https://man.dragonflybsd.org/?command=pipe2
https://man.netbsd.org/pipe.2
https://man.openbsd.org/pipe.2
https://docs.oracle.com/cd/E88353_01/html/E37841/pipe2-2.html
https://illumos.org/man/2/pipe2
https://www.gnu.org/software/gnulib/manual/html_node/pipe2.html

Closes #16987
This commit is contained in:
Andy Pan 2025-04-06 20:37:10 +08:00 committed by Daniel Stenberg
parent 8988f33f62
commit 131a2fd5aa
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
6 changed files with 23 additions and 2 deletions

View file

@ -192,6 +192,15 @@ set(HAVE_NETINET_UDP_H 1)
set(HAVE_NET_IF_H 1)
set(HAVE_OPENDIR 1)
set(HAVE_PIPE 1)
if(APPLE OR
CYGWIN)
set(HAVE_PIPE2 0)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR
CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR
CMAKE_SYSTEM_NAME STREQUAL "NetBSD" OR
CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
set(HAVE_PIPE2 1)
endif()
set(HAVE_POLL 1)
set(HAVE_POLL_H 1)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")

View file

@ -139,6 +139,7 @@ set(HAVE_NETINET_TCP_H 0)
set(HAVE_NETINET_UDP_H 0)
set(HAVE_NET_IF_H 0)
set(HAVE_PIPE 0)
set(HAVE_PIPE2 0)
set(HAVE_POLL 0)
set(HAVE_POLL_H 0)
set(HAVE_POSIX_STRERROR_R 0)