Skip to content

socketpair: support pipe2 where available #16987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed

Conversation

panjf2000
Copy link
Contributor

@panjf2000 panjf2000 commented Apr 6, 2025

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

@bagder
Copy link
Member

bagder commented Apr 6, 2025

For the record: we prefer using eventfd, so this is only really a win for systems without eventfd but with pipe2()

@panjf2000
Copy link
Contributor Author

panjf2000 commented Apr 6, 2025

For the record: we prefer using eventfd, so this is only really a win for systems without eventfd but with pipe2()

True, check out https://www.gnu.org/software/gnulib/manual/html_node/eventfd.html

Aside from that, users are allowed to disable eventfd manually by:

  • cmake: -DHAVE_EVENTFD=0
  • configure: export ac_cv_func_eventfd=0

In that case, pipe2 can also come to the rescue.

Co-authored-by: Viktor Szakats <vszakats@users.noreply.github.com>
@panjf2000 panjf2000 requested a review from vszakats April 7, 2025 07:59
@bagder bagder closed this in 131a2fd Apr 7, 2025
@bagder
Copy link
Member

bagder commented Apr 7, 2025

Thanks!

@panjf2000 panjf2000 deleted the pipe2 branch April 7, 2025 10:54
nbaws pushed a commit to nbaws/curl that referenced this pull request Apr 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants