fix: add check for `EWOULDBLOCK` (#6350) (#6566)

(cherry picked from commit 4506d20136)
This commit is contained in:
Yat Ho 2024-02-11 10:14:24 +08:00 committed by GitHub
parent 0f4a7a2a53
commit 04244310da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 13 deletions

View File

@ -27,17 +27,6 @@
#include "tr-utp.h"
#include "utils.h" // for _()
#ifdef _WIN32
#undef EAGAIN
#define EAGAIN WSAEWOULDBLOCK
#undef EINTR
#define EINTR WSAEINTR
#undef EINPROGRESS
#define EINPROGRESS WSAEINPROGRESS
#undef EPIPE
#define EPIPE WSAECONNRESET
#endif
#define tr_logAddErrorIo(io, msg) tr_logAddError(msg, (io)->display_name())
#define tr_logAddWarnIo(io, msg) tr_logAddWarn(msg, (io)->display_name())
#define tr_logAddDebugIo(io, msg) tr_logAddDebug(msg, (io)->display_name())
@ -49,7 +38,12 @@ namespace
// since that's what peer-io does by default anyway.
[[nodiscard]] auto constexpr canRetryFromError(int error_code) noexcept
{
return error_code == 0 || error_code == EAGAIN || error_code == EINTR || error_code == EINPROGRESS;
#ifdef _WIN32
return error_code == 0 || error_code == WSAEWOULDBLOCK || error_code == WSAEINTR || error_code == WSAEINPROGRESS;
#else
return error_code == 0 || error_code == EAGAIN || error_code == EWOULDBLOCK || error_code == EINTR ||
error_code == EINPROGRESS;
#endif
}
size_t get_desired_output_buffer_size(tr_peerIo const* io, uint64_t now)
@ -412,7 +406,7 @@ size_t tr_peerIo::try_read(size_t max)
// Do not write more than the bandwidth allows.
// If there is no bandwidth left available, disable writes.
max = bandwidth().clamp(TR_DOWN, max);
max = bandwidth().clamp(Dir, max);
if (max == 0)
{
set_enabled(Dir, false);