Skip to content

Commit 254bea4

Browse files
committed
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.
1 parent 7a7bfa1 commit 254bea4

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/socket_poller.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ int zmq::socket_poller_t::wait (zmq::socket_poller_t::event_t *events_,
559559
if (rc == -1 && errno == EINTR) {
560560
return -1;
561561
}
562+
562563
errno_assert (rc >= 0);
563564

564565
// Receive the signal from pollfd

src/windows.hpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#endif
2525
#endif
2626

27+
#include "err.hpp"
2728
#include <winsock2.h>
2829
#include <windows.h>
2930
#include <mswsock.h>
@@ -57,7 +58,26 @@ struct tcp_keepalive
5758
#if defined ZMQ_IOTHREAD_POLLER_USE_POLL || defined ZMQ_POLL_BASED_ON_POLL
5859
static inline int poll (struct pollfd *pfd, unsigned long nfds, int timeout)
5960
{
60-
return WSAPoll (pfd, nfds, timeout);
61+
int rc = WSAPoll (pfd, nfds, timeout);
62+
if (rc == -1)
63+
{
64+
int wsaError = WSAGetLastError ();
65+
switch (wsaError)
66+
{
67+
// let these conditions appear as an interrupted call to
68+
// simplify downstream error processing.
69+
case WSAENETDOWN:
70+
case WSAENOBUFS:
71+
errno = EINTR;
72+
break;
73+
74+
default:
75+
errno = zmq::wsa_error_to_errno(wsaError);
76+
break;
77+
}
78+
}
79+
80+
return rc;
6181
}
6282
#endif
6383

0 commit comments

Comments
 (0)