mirror of
https://github.com/curl/curl.git
synced 2026-08-12 15:50:55 +03:00
socket: introduce SOCK_EAGAIN() and use it
To contain the logic of checking for both `EWOULDBLOCK` and/or `EAGAIN` depending 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 `EAGAIN` is consistently not checked on Windows, where headers defined it, but `SOCKERRNO` never returns it, because curl maps it to `WSAGetLastError()`. If they map to the same value, checking them both in an `if` expression trips GCC warning `-Wlogical-op` (the same way it triggers duplicate case value error in `switch`). Also: - replace two `switch()` statements with the new macro. - tests/server/sws: make two outliers use the new macro that were only checking for `EWOULDBLOCK` before this patch, in `connect_to()`. - move variables to the left-side of expressions, where missing. - rustls: use a variant of this macro that uses raw `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 to https://docs.rs/system_error/0.2.0/system_error/, which would be probably incorrect. Notes: - it's probably a good idea to assign `SOCKERRNO` to a variable before passing it to this macro. Cherry-picked from #21893 Closes #21992
This commit is contained in:
parent
7c51a33877
commit
879a1514c3
7 changed files with 63 additions and 95 deletions
|
|
@ -109,7 +109,7 @@ size_t tool_read_cb(char *buffer, size_t sz, size_t nmemb, void *userdata)
|
|||
#ifndef CURL_WINDOWS_UWP
|
||||
rc = sread(per->infd, buffer, curlx_uztosi(sz * nmemb));
|
||||
if(rc < 0) {
|
||||
if(SOCKERRNO == SOCKEWOULDBLOCK) {
|
||||
if(SOCK_EAGAIN(SOCKERRNO)) {
|
||||
errno = 0;
|
||||
config->readbusy = TRUE;
|
||||
return CURL_READFUNC_PAUSE;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue