From 254bea4910ccad0ee52ddc73adaceb857c1b8b91 Mon Sep 17 00:00:00 2001 From: Denis Zibarev <9913878+dz-fsd@users.noreply.github.com> Date: Mon, 21 Jul 2025 14:55:46 +0800 Subject: [PATCH 1/2] Problem: zmq_abort() may be called on Windows if polling fails Solution: On Windows platform, implement custom WSA error to errno translation in the poll() function. The goal is to make Windows-specific poll() to appear more Unixy to the callers. --- src/socket_poller.cpp | 1 + src/windows.hpp | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/socket_poller.cpp b/src/socket_poller.cpp index b9eab821a8..54519cd304 100644 --- a/src/socket_poller.cpp +++ b/src/socket_poller.cpp @@ -559,6 +559,7 @@ int zmq::socket_poller_t::wait (zmq::socket_poller_t::event_t *events_, if (rc == -1 && errno == EINTR) { return -1; } + errno_assert (rc >= 0); // Receive the signal from pollfd diff --git a/src/windows.hpp b/src/windows.hpp index 3ecec4c652..7bd49c7f68 100644 --- a/src/windows.hpp +++ b/src/windows.hpp @@ -24,6 +24,7 @@ #endif #endif +#include "err.hpp" #include #include #include @@ -57,7 +58,26 @@ struct tcp_keepalive #if defined ZMQ_IOTHREAD_POLLER_USE_POLL || defined ZMQ_POLL_BASED_ON_POLL static inline int poll (struct pollfd *pfd, unsigned long nfds, int timeout) { - return WSAPoll (pfd, nfds, timeout); + int rc = WSAPoll (pfd, nfds, timeout); + if (rc == -1) + { + int wsaError = WSAGetLastError (); + switch (wsaError) + { + // let these conditions appear as an interrupted call to + // simplify downstream error processing. + case WSAENETDOWN: + case WSAENOBUFS: + errno = EINTR; + break; + + default: + errno = zmq::wsa_error_to_errno(wsaError); + break; + } + } + + return rc; } #endif From 1497e6f8ef5546d6bae9124fe503f9e1032eaa7f Mon Sep 17 00:00:00 2001 From: Denis Zibarev <9913878+dz-fsd@users.noreply.github.com> Date: Sun, 27 Jul 2025 18:29:52 +0800 Subject: [PATCH 2/2] Update code formatting --- src/windows.hpp | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/windows.hpp b/src/windows.hpp index 7bd49c7f68..f5abf556b4 100644 --- a/src/windows.hpp +++ b/src/windows.hpp @@ -59,23 +59,21 @@ struct tcp_keepalive static inline int poll (struct pollfd *pfd, unsigned long nfds, int timeout) { int rc = WSAPoll (pfd, nfds, timeout); - if (rc == -1) - { - int wsaError = WSAGetLastError (); - switch (wsaError) - { - // let these conditions appear as an interrupted call to - // simplify downstream error processing. - case WSAENETDOWN: - case WSAENOBUFS: - errno = EINTR; - break; - - default: - errno = zmq::wsa_error_to_errno(wsaError); - break; + if (rc == -1) { + int wsaError = WSAGetLastError (); + switch (wsaError) { + // let these conditions appear as an interrupted call to + // simplify downstream error processing. + case WSAENETDOWN: + case WSAENOBUFS: + errno = EINTR; + break; + + default: + errno = zmq::wsa_error_to_errno (wsaError); + break; } - } + } return rc; }