Commit 13ef1e4f authored by Martin Hurton's avatar Martin Hurton

Make wsa_error_to_errno pure function

parent a8f9a0d8
...@@ -214,46 +214,36 @@ void zmq::win_error (char *buffer_, size_t buffer_size_) ...@@ -214,46 +214,36 @@ void zmq::win_error (char *buffer_, size_t buffer_size_)
zmq_assert (rc); zmq_assert (rc);
} }
void zmq::wsa_error_to_errno () int zmq::wsa_error_to_errno (int errcode)
{ {
int errcode = WSAGetLastError ();
switch (errcode) { switch (errcode) {
case WSAEINPROGRESS: case WSAEINPROGRESS:
errno = EAGAIN; return EAGAIN;
return;
case WSAEBADF: case WSAEBADF:
errno = EBADF; return EBADF;
return;
case WSAEINVAL: case WSAEINVAL:
errno = EINVAL; return EINVAL;
return;
case WSAEMFILE: case WSAEMFILE:
errno = EMFILE; return EMFILE;
return;
case WSAEFAULT: case WSAEFAULT:
errno = EFAULT; return EFAULT;
return;
case WSAEPROTONOSUPPORT: case WSAEPROTONOSUPPORT:
errno = EPROTONOSUPPORT; return EPROTONOSUPPORT;
return;
case WSAENOBUFS: case WSAENOBUFS:
errno = ENOBUFS; return ENOBUFS;
return;
case WSAENETDOWN: case WSAENETDOWN:
errno = ENETDOWN; return ENETDOWN;
return;
case WSAEADDRINUSE: case WSAEADDRINUSE:
errno = EADDRINUSE; return EADDRINUSE;
return;
case WSAEADDRNOTAVAIL: case WSAEADDRNOTAVAIL:
errno = EADDRNOTAVAIL; return EADDRNOTAVAIL;
return;
case WSAEAFNOSUPPORT: case WSAEAFNOSUPPORT:
errno = EAFNOSUPPORT; return EAFNOSUPPORT;
return;
default: default:
wsa_assert (false); wsa_assert (false);
} }
// Not reachable
return 0;
} }
#endif #endif
...@@ -57,7 +57,7 @@ namespace zmq ...@@ -57,7 +57,7 @@ namespace zmq
const char *wsa_error (); const char *wsa_error ();
const char *wsa_error_no (int no_); const char *wsa_error_no (int no_);
void win_error (char *buffer_, size_t buffer_size_); void win_error (char *buffer_, size_t buffer_size_);
void wsa_error_to_errno (); int wsa_error_to_errno (int errcode);
} }
// Provides convenient way to check WSA-style errors on Windows. // Provides convenient way to check WSA-style errors on Windows.
......
...@@ -193,7 +193,7 @@ int zmq::tcp_connecter_t::open () ...@@ -193,7 +193,7 @@ int zmq::tcp_connecter_t::open ()
s = open_socket (addr->resolved.tcp_addr->family (), SOCK_STREAM, IPPROTO_TCP); s = open_socket (addr->resolved.tcp_addr->family (), SOCK_STREAM, IPPROTO_TCP);
#ifdef ZMQ_HAVE_WINDOWS #ifdef ZMQ_HAVE_WINDOWS
if (s == INVALID_SOCKET) { if (s == INVALID_SOCKET) {
wsa_error_to_errno (); errno = wsa_error_to_errno (WSAGetLastError ());
return -1; return -1;
} }
#else #else
...@@ -226,7 +226,7 @@ int zmq::tcp_connecter_t::open () ...@@ -226,7 +226,7 @@ int zmq::tcp_connecter_t::open ()
errno = EINPROGRESS; errno = EINPROGRESS;
return -1; return -1;
} }
wsa_error_to_errno (); errno = wsa_error_to_errno (WSAGetLastError ());
#else #else
if (rc == -1 && errno == EINTR) { if (rc == -1 && errno == EINTR) {
errno = EINPROGRESS; errno = EINPROGRESS;
......
...@@ -156,7 +156,7 @@ int zmq::tcp_listener_t::set_address (const char *addr_) ...@@ -156,7 +156,7 @@ int zmq::tcp_listener_t::set_address (const char *addr_)
s = open_socket (address.family (), SOCK_STREAM, IPPROTO_TCP); s = open_socket (address.family (), SOCK_STREAM, IPPROTO_TCP);
#ifdef ZMQ_HAVE_WINDOWS #ifdef ZMQ_HAVE_WINDOWS
if (s == INVALID_SOCKET) if (s == INVALID_SOCKET)
wsa_error_to_errno (); errno = wsa_error_to_errno (WSAGetLastError ());
#endif #endif
// IPv6 address family not supported, try automatic downgrade to IPv4. // IPv6 address family not supported, try automatic downgrade to IPv4.
...@@ -170,7 +170,7 @@ int zmq::tcp_listener_t::set_address (const char *addr_) ...@@ -170,7 +170,7 @@ int zmq::tcp_listener_t::set_address (const char *addr_)
#ifdef ZMQ_HAVE_WINDOWS #ifdef ZMQ_HAVE_WINDOWS
if (s == INVALID_SOCKET) { if (s == INVALID_SOCKET) {
wsa_error_to_errno (); errno = wsa_error_to_errno (WSAGetLastError ());
return -1; return -1;
} }
// On Windows, preventing sockets to be inherited by child processes. // On Windows, preventing sockets to be inherited by child processes.
...@@ -203,7 +203,7 @@ int zmq::tcp_listener_t::set_address (const char *addr_) ...@@ -203,7 +203,7 @@ int zmq::tcp_listener_t::set_address (const char *addr_)
rc = bind (s, address.addr (), address.addrlen ()); rc = bind (s, address.addr (), address.addrlen ());
#ifdef ZMQ_HAVE_WINDOWS #ifdef ZMQ_HAVE_WINDOWS
if (rc == SOCKET_ERROR) { if (rc == SOCKET_ERROR) {
wsa_error_to_errno (); errno = wsa_error_to_errno (WSAGetLastError ());
return -1; return -1;
} }
#else #else
...@@ -215,7 +215,7 @@ int zmq::tcp_listener_t::set_address (const char *addr_) ...@@ -215,7 +215,7 @@ int zmq::tcp_listener_t::set_address (const char *addr_)
rc = listen (s, options.backlog); rc = listen (s, options.backlog);
#ifdef ZMQ_HAVE_WINDOWS #ifdef ZMQ_HAVE_WINDOWS
if (rc == SOCKET_ERROR) { if (rc == SOCKET_ERROR) {
wsa_error_to_errno (); errno = wsa_error_to_errno (WSAGetLastError ());
return -1; return -1;
} }
#else #else
......
...@@ -853,17 +853,15 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_) ...@@ -853,17 +853,15 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
#if defined ZMQ_HAVE_WINDOWS #if defined ZMQ_HAVE_WINDOWS
int rc = select (0, &inset, &outset, &errset, ptimeout); int rc = select (0, &inset, &outset, &errset, ptimeout);
if (unlikely (rc == SOCKET_ERROR)) { if (unlikely (rc == SOCKET_ERROR)) {
zmq::wsa_error_to_errno (); errno = zmq::wsa_error_to_errno (WSAGetLastError ());
if (errno == ENOTSOCK) wsa_assert (errno == ENOTSOCK);
return -1; return -1;
wsa_assert (false);
} }
#else #else
int rc = select (maxfd + 1, &inset, &outset, &errset, ptimeout); int rc = select (maxfd + 1, &inset, &outset, &errset, ptimeout);
if (unlikely (rc == -1)) { if (unlikely (rc == -1)) {
if (errno == EINTR || errno == EBADF) errno_assert (errno == EINTR || errno == EBADF);
return -1; return -1;
errno_assert (false);
} }
#endif #endif
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment