From a29672070d9acdf3e01223514e42ed656958be8e Mon Sep 17 00:00:00 2001 From: Egor Date: Fri, 13 Jun 2025 03:40:42 +0300 Subject: [PATCH] check EAGAIN/EWOULDBLOCK directly --- src/main.cpp | 2 +- src/net.cpp | 4 ++-- src/netsock.h | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 28e56ab..a979e4e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -72,7 +72,7 @@ static void accept_from_sock(struct listener *listener) socklen_t len = sizeof(addr); uv_os_sock_t fd = accept4(listener->fd, (struct sockaddr *)&addr, &len, SOCK_CLOEXEC | SOCK_NONBLOCK); if (fd == -1) { - if (!net_wouldblock()) + if (errno != EAGAIN && errno != EWOULDBLOCK) perror("accept4"); break; } diff --git a/src/net.cpp b/src/net.cpp index 233a02e..4bd3862 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -196,7 +196,7 @@ void recvProc(struct client_data *cl) { return; // Error case -1: - if(!net_wouldblock()){ + if (errno != EAGAIN && errno != EWOULDBLOCK) { perror("recv"); killConnection(cl, 0); } else { @@ -255,7 +255,7 @@ static int sendClientRaw(struct client_data *cl, const char *buf, size_t len) if (!rv) return -1; if (rv == -1) { - if (net_wouldblock()) { + if (errno == EAGAIN || errno == EWOULDBLOCK) { cl->want_write_for_write = 1; return len; } else { diff --git a/src/netsock.h b/src/netsock.h index 571b2ba..981a9df 100644 --- a/src/netsock.h +++ b/src/netsock.h @@ -45,5 +45,4 @@ #include #include #include -#define net_wouldblock() (errno == EAGAIN || errno == EWOULDBLOCK) #endif -- 2.56.0