socket: introduce SOCK_EAGAIN() and use it#21992
Closed
vszakats wants to merge 41 commits into
Closed
Conversation
```
/Users/runner/work/curl/curl/lib/cf-socket.c: In function 'cf_socket_send':
/Users/runner/work/curl/curl/lib/cf-socket.c:1498:36: error: logical 'or' of equal expressions [-Werror=logical-op]
1498 | (SOCKEWOULDBLOCK == sockerr) ||
| ^~
/Users/runner/work/curl/curl/lib/cf-socket.c: In function 'cf_socket_recv':
/Users/runner/work/curl/curl/lib/cf-socket.c:1564:36: error: logical 'or' of equal expressions [-Werror=logical-op]
1564 | (SOCKEWOULDBLOCK == sockerr) ||
| ^~
In file included from /Users/runner/work/curl/curl/bld/lib/CMakeFiles/libcurl_shared.dir/Unity/unity_0_c.c:331:
/Users/runner/work/curl/curl/lib/socketpair.c: In function 'Curl_wakeup_signal':
/Users/runner/work/curl/curl/lib/socketpair.c:329:35: error: logical 'or' of equal expressions [-Werror=logical-op]
329 | if((err == SOCKEWOULDBLOCK) || (err == EAGAIN))
| ^~
```
```
/Users/runner/work/curl/curl/lib/socketpair.c:329:15: error: equality comparison with extraneous parentheses [-Werror,-Wparentheses-equality]
if((err == SOCKEWOULDBLOCK)
~~~~^~~~~~~~~~~~~~~~~~
/Users/runner/work/curl/curl/lib/socketpair.c:329:15: note: remove extraneous parentheses around the comparison to silence this warning
if((err == SOCKEWOULDBLOCK)
~ ^ ~
/Users/runner/work/curl/curl/lib/socketpair.c:329:15: note: use '=' to turn this equality comparison into an assignment
if((err == SOCKEWOULDBLOCK)
^~
=
/Users/runner/work/curl/curl/lib/socketpair.c:359:21: error: equality comparison with extraneous parentheses [-Werror,-Wparentheses-equality]
if((SOCKERRNO == SOCKEWOULDBLOCK)
~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/Users/runner/work/curl/curl/lib/socketpair.c:359:21: note: remove extraneous parentheses around the comparison to silence this warning
if((SOCKERRNO == SOCKEWOULDBLOCK)
~ ^ ~
/Users/runner/work/curl/curl/lib/socketpair.c:359:21: note: use '=' to turn this equality comparison into an assignment
if((SOCKERRNO == SOCKEWOULDBLOCK)
^~
=
2 errors generated.
```
https://github.com/curl/curl/actions/runs/27107980068/job/80000462156?pr=21893
comparing to raw EWOULDBLOCK may not be working as expected on Windows. Based on this: https://doc.rust-lang.org/std/io/struct.Error.html#method.last_os_error Rust doesn't seem to be returning the socket error on Windows, but a GetLastError() which does not return EWOULDBLOCK or SOCKEWOULDBLOCK.
There was an unprotected unconditional use in src. Also in vquic and socketpair, on conditions.
SOCK_EWOULDBLOCK_EAGAIN(), use itSOCK_EAGAIN(), use it
SOCK_EAGAIN(), use itSOCK_EAGAIN() and use it
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
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.
To contain the logic of checking for both
EWOULDBLOCKand/orEAGAINdepending on platform/availability. Also to avoid checking for both if
they mapp to the same value, and to avoid PP guards around use.
This also ensures
EAGAINis consistently not checked on Windows, whereheaders defined it, but
SOCKERRNOnever returns it, because curl mapsit to
WSAGetLastError().If they map to the same value, checking them both in an
ifexpressiontrips GCC warning
-Wlogical-op(the same way it triggers duplicatecase value error in
switch).Also:
switch()statements with the new macro.checking for
EWOULDBLOCKbefore this patch, inconnect_to().EWOULDBLOCK.Tried tracing it back to the origins, but I couldn't figure out if
this is working as expected on all supported Windows versions in
Rust. It seems to be using
GetLastError(), according tohttps://docs.rs/system_error/0.2.0/system_error/, which would be
probably incorrect.
Notes:
SOCKERRNOto a variable beforepassing it to this macro.
Cherry-picked from #21893
https://github.com/curl/curl/pull/21992/files?w=1
SOCK_EWOULDBLOCK_EAGAIN()for the macro? I figure it's nice to include both namesit's covering, but don't feel strongly about it. → [trying
SOCK_EAGAIN()for short]switchinto anifand use this macro? [DONE, also for another instance]have
EWOULDBLOCKbut do haveEAGAIN. This wasn't consistentlysupported and this patch leaves it as-is. If this causes an issue, it
should be easy to support this case with the new macro.
Feature request : Improve portability libssh2/libssh2#171
Add an EWOULDBLOCK check for better portability libssh2/libssh2#172
libssh2/libssh2@92f7686
On a second read this seem overkill, and
EWOULDBLOCKwas added for VMS-onlythen later extended to more platforms but keeping a check for
EWOULDBLOCK.POSIX should have this macro. Also curl never handled a build without it.