-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
cf-socket: optimize curlx_nonblock() and check its return error #13942
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
Conversation
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 agree with you that saving syscalls in a filter that is involved heavily is a good idea. But for this change to be reliable, it would really be necessary that the socket is only manipulated by the filter itself.
Unfortunately, this is not the case in libcurl for historical reasons. If you scan the code for calls of curlx_nonblock()
, you'll find several locations outside cf-socket.c.
The other observation I had when making the shutdown change in cf-socket is that Windows sometimes seems to block on receives unless the setting to nonblocking just before did indeed succeed. That is the reason for the final receive only being done then.
Due to this, I think using a flag for skipping the curx_nonblock()
during shutdown will introduce strange edge behaviour, making it issues hard to debug.
Thanks for sharing the particularity of |
I might be wrong, but in cf-socket.c I see the flag only set, but never used outside of the shutdown function? |
It's used in |
2879845
to
d2760ac
Compare
Hi @icing, would you take a glance at the latest code changes? |
Thanks for the ping. Looking at the diff, I like the optimization in The I think you should remove |
Done. |
sock_nonblocking
for cf_socket_ctx
I am sure @bagder will get right to it after Sweden celebrates midsummer. |
OK, thanks for the notice! Have a good one! |
Thanks! |
Updates:
Due to the particularity of
cf_socket_shutdown()
, we've decided not to usesock_nonblocking
forcf_socket_shutdown()
. Meanwhile, we currently don't check if the socket created bycf_socket_open
is non-blocking when connecting, which can lead to unexpected behaviors (blocking connect), therefore, we can leveragesock_nonblocking
for these cases. Check out #13942 (comment)We sometimes need to check if a socket is non-blocking to determine the subsequent actions, such as the
cf_socket_shutdown()
, which sets the non-blocking flag on the socket and then drains its buffer during a shutdown. It has to use system calls on the socket anyway because there is no way to tell if the current socket is non-blocking, therefore, adding a new flag for structcf_socket_ctx
to indicate if the socket is non-blocking will help us eliminate some redundant system calls.This PR mainly does two things:
sock_nonblocking
forcf_socket_ctx
and assign proper values to it (also reference it) accordinglycurlx_nonblock()
, make it handle errors properly, and avoid needless system calls