-
Notifications
You must be signed in to change notification settings - Fork 23.5k
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
Enable SOCK_NONBLOCK on system call socket() #13093
base: unstable
Are you sure you want to change the base?
Conversation
9789896
to
97bfc8e
Compare
src/anet.c
Outdated
#ifdef SOCK_NONBLOCK | ||
if (flags & ANET_CONNECT_NONBLOCK) p->ai_socktype |= SOCK_NONBLOCK; | ||
#else | ||
if (flags & ANET_CONNECT_NONBLOCK) sockflags |= O_NONBLOCK; | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm confused.
why do we have to pass two different flags for the same purpose, rather than let anetCreateSocket handle it implicitly with ifdefs?
as far as i remember that was your previous approach, why did you abandon it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we do care about CLOEXEC for the listen sockets, maybe we should handle them like NONBLOCK REUSEADDR, and let anetCreateSocket get flags and handle them all internally?
Did I misunderstand your previous comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe i misunderstood something and my comment isn't applicable..
when i gave that comment it was on a piece of code that explicitly called anetCloexec, and you added an #ifdef
for SOCK_CLOEXEC, but code was far from the logical "#else. so i'm trying to suggest that all the logic about these 3 flags, (whether to pass them as flags to
socketor call an explicit system call after it), should all be be hidden inside
anetCreateSocket` that abstracts all the nuances about how to use the system calls.
i hope it's doable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check out the latest commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oranagra Any thoughts about the latest commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping @oranagra
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping @oranagra
|
…ockets Signed-off-by: Andy Pan <i@andypan.me>
What this PR mainly does is:
anetCreateSocket()
to make it more generic for more socket arguments, and useSOCK_NONBLOCK
if available, which will reduce two system calls (F_GETFL
andF_SETFL
) of enabling the non-blocking mode on each newly created socket.anetUnixGenericConnect()
that callsanetCreateSocket()
.SOCK_NONBLOCK
for system callsocket()
is supported on most UNIX-like platforms (linux
,dragonfly
,freebsd
,netbsd
,openbsd
,solaris
, etc.). This improvement will significantly reduce the system calls considering how massivelyanetTcpGenericConnect()
will be called when needed.As for the cleanup,
anetUnixGenericConnect
was introduced in c61e692 and the only reference back then was from thecreateClient()
inredis-benchmark.c
which had been removed in ec8f066 and made it the dead code. Most of that dead code was also cleaned up in f657315, and it seems that theanetUnixGenericConnect
got left out. Therefore, I also cleaned it up, but I'm not so certain about doing this cleanup in this PR. Maybe you would prefer to do it in a separate PR?References