From d2687af73ad2e3db2c70695d5fbdd537278bfc0a Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 8 Jun 2026 04:22:33 +0200 Subject: [PATCH] merge checks on Win/non-Win --- lib/cf-socket.c | 33 ++++++++++++--------------------- lib/socketpair.c | 30 ++++++++++-------------------- src/tool_cb_rea.c | 2 +- 3 files changed, 23 insertions(+), 42 deletions(-) diff --git a/lib/cf-socket.c b/lib/cf-socket.c index edeeee0414..3f3df996df 100644 --- a/lib/cf-socket.c +++ b/lib/cf-socket.c @@ -1559,17 +1559,12 @@ static CURLcode cf_socket_send(struct Curl_cfilter *cf, struct Curl_easy *data, if(!curlx_sztouz(rv, pnwritten)) { int sockerr = SOCKERRNO; - if( -#ifdef USE_WINSOCK - /* This is how Windows does it */ - (sockerr == SOCKEWOULDBLOCK) -#else - /* errno may be EWOULDBLOCK or on some systems EAGAIN when it returned - due to its inability to send off data without blocking. We therefore - treat both error codes the same here */ - SOCK_EWOULDBLOCK_EAGAIN(sockerr) || - (sockerr == SOCKEINTR) || - (sockerr == SOCKEINPROGRESS) + /* errno may be EWOULDBLOCK or on some systems EAGAIN when it returned + due to its inability to send off data without blocking. We therefore + treat both error codes the same here */ + if(SOCK_EWOULDBLOCK_EAGAIN(sockerr) +#ifndef USE_WINSOCK + || (sockerr == SOCKEINTR) || (sockerr == SOCKEINPROGRESS) #endif ) { /* EWOULDBLOCK */ @@ -1625,16 +1620,12 @@ static CURLcode cf_socket_recv(struct Curl_cfilter *cf, struct Curl_easy *data, if(!curlx_sztouz(rv, pnread)) { int sockerr = SOCKERRNO; - if( -#ifdef USE_WINSOCK - /* This is how Windows does it */ - (sockerr == SOCKEWOULDBLOCK) -#else - /* errno may be EWOULDBLOCK or on some systems EAGAIN when it returned - due to its inability to send off data without blocking. We therefore - treat both error codes the same here */ - SOCK_EWOULDBLOCK_EAGAIN(sockerr) || - (sockerr == SOCKEINTR) + /* errno may be EWOULDBLOCK or on some systems EAGAIN when it returned + due to its inability to send off data without blocking. We therefore + treat both error codes the same here */ + if(SOCK_EWOULDBLOCK_EAGAIN(sockerr) +#ifndef USE_WINSOCK + || (sockerr == SOCKEINTR) #endif ) { /* EWOULDBLOCK */ diff --git a/lib/socketpair.c b/lib/socketpair.c index 8db80d1833..404ceac877 100644 --- a/lib/socketpair.c +++ b/lib/socketpair.c @@ -232,16 +232,12 @@ static int wakeup_inet(curl_socket_t socks[2], bool nonblocking) /* Do not block forever */ if(curlx_timediff_ms(curlx_now(), start) > (60 * 1000)) goto error; - if( -#ifdef USE_WINSOCK - /* This is how Windows does it */ - (sockerr == SOCKEWOULDBLOCK) -#else - /* errno may be EWOULDBLOCK or on some systems EAGAIN when it - returned due to its inability to send off data without - blocking. We therefore treat both error codes the same here */ - SOCK_EWOULDBLOCK_EAGAIN(sockerr) || - (sockerr == SOCKEINTR) || (sockerr == SOCKEINPROGRESS) + /* errno may be EWOULDBLOCK or on some systems EAGAIN when it + returned due to its inability to send off data without + blocking. We therefore treat both error codes the same here */ + if(SOCK_EWOULDBLOCK_EAGAIN(sockerr) +#ifndef USE_WINSOCK + || (sockerr == SOCKEINTR) || (sockerr == SOCKEINPROGRESS) #endif ) { continue; @@ -320,15 +316,12 @@ int Curl_wakeup_signal(curl_socket_t socks[2]) err = 0; if(wakeup_write(socks[1], buf, sizeof(buf)) < 0) { err = SOCKERRNO; -#ifdef USE_WINSOCK - if(err == SOCKEWOULDBLOCK) - err = 0; /* wakeup is already ongoing */ -#else +#ifndef USE_WINSOCK if(err == SOCKEINTR) continue; +#endif if(SOCK_EWOULDBLOCK_EAGAIN(err)) err = 0; /* wakeup is already ongoing */ -#endif } break; } @@ -346,15 +339,12 @@ CURLcode Curl_wakeup_consume(curl_socket_t socks[2], bool all) if(!rc) break; else if(rc < 0) { -#ifdef USE_WINSOCK - if(SOCKERRNO == SOCKEWOULDBLOCK) - break; -#else +#ifndef USE_WINSOCK if(SOCKERRNO == SOCKEINTR) continue; +#endif if(SOCK_EWOULDBLOCK_EAGAIN(SOCKERRNO)) break; -#endif result = CURLE_READ_ERROR; break; } diff --git a/src/tool_cb_rea.c b/src/tool_cb_rea.c index a818d0804d..9b75d4eae5 100644 --- a/src/tool_cb_rea.c +++ b/src/tool_cb_rea.c @@ -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_EWOULDBLOCK_EAGAIN(SOCKERRNO)) { errno = 0; config->readbusy = TRUE; return CURL_READFUNC_PAUSE;