-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
socket: exploit SOCK_NONBLOCK
to eliminate extra system calls
#13855
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SOCK_NONBLOCK
to eliminate extra system call
SOCK_NONBLOCK
to eliminate extra system callSOCK_NONBLOCK
to eliminate extra system calls
Please provide a description explaining what this change does and why we want it. |
Done, please check out the top comment! @bagder |
2acc06a
to
80f9bfb
Compare
While you're here, could you take a look at this PR? @bagder |
bagder
reviewed
Jun 4, 2024
Every time function `cf_socket_open()` is called to create a socket, `curlx_nonblock()` is called to make that socket non-blocking. And `curlx_nonblock()` will cost us 1 or 2 system calls (2 for `fcntl()`, 1 for `ioctl()`, etc.), meanwhile, tucking `SOCK_NONBLOCK` and `SOCK_CLOEXEC` into the `type` argument for `socket()` is widely supported across UNIX-like OS: Linux, *BSD, Solaris, etc. With that ability, we can save 1 or 2 system calls on each socket. Another change in this PR is to eliminate the redundant `curlx_nonblock()` call on the socket in `cf_udp_setup_quic()` as that socket created by `cf_socket_open()` is already non-blocking. Ref: https://man7.org/linux/man-pages/man2/socket.2.html https://man.freebsd.org/cgi/man.cgi?socket(2) https://man.dragonflybsd.org/?command=socket§ion=2 https://man.netbsd.org/socket.2 https://man.openbsd.org/socket https://docs.oracle.com/cd/E88353_01/html/E37843/socket-3c.html https://illumos.org/man/3SOCKET/socket ...
bagder
approved these changes
Jun 4, 2024
Thanks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Every time function
cf_socket_open()
is called to create a socket,curlx_nonblock()
is called to make that socket non-blocking. Andcurlx_nonblock()
will cost us 1 or 2 system calls (2 forfcntl()
, 1 forioctl()
, etc.), meanwhile, tuckingSOCK_NONBLOCK
andSOCK_CLOEXEC
into thetype
argument forsocket()
is widely supported across UNIX-like OS: Linux, *BSD, Solaris, etc. With that ability, we can save 1 or 2 system calls on each socket.Another change in this PR is to eliminate the redundant
curlx_nonblock()
call on the socket incf_udp_setup_quic()
as that socket created bycf_socket_open()
is already non-blocking.Ref: