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_)
zmq_assert (rc);
}
void zmq::wsa_error_to_errno ()
int zmq::wsa_error_to_errno (int errcode)
{
int errcode = WSAGetLastError ();
switch (errcode) {
case WSAEINPROGRESS:
errno = EAGAIN;
return;
return EAGAIN;
case WSAEBADF:
errno = EBADF;
return;
return EBADF;
case WSAEINVAL:
errno = EINVAL;
return;
return EINVAL;
case WSAEMFILE:
errno = EMFILE;
return;
return EMFILE;
case WSAEFAULT:
errno = EFAULT;
return;
return EFAULT;
case WSAEPROTONOSUPPORT:
errno = EPROTONOSUPPORT;
return;
return EPROTONOSUPPORT;
case WSAENOBUFS:
errno = ENOBUFS;
return;
return ENOBUFS;
case WSAENETDOWN:
errno = ENETDOWN;
return;
return ENETDOWN;
case WSAEADDRINUSE:
errno = EADDRINUSE;
return;
return EADDRINUSE;
case WSAEADDRNOTAVAIL:
errno = EADDRNOTAVAIL;
return;
return EADDRNOTAVAIL;
case WSAEAFNOSUPPORT:
errno = EAFNOSUPPORT;
return;
return EAFNOSUPPORT;
default:
wsa_assert (false);
}
// Not reachable
return 0;
}
#endif
......@@ -57,7 +57,7 @@ namespace zmq
const char *wsa_error ();
const char *wsa_error_no (int no_);
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.
......
......@@ -193,7 +193,7 @@ int zmq::tcp_connecter_t::open ()
s = open_socket (addr->resolved.tcp_addr->family (), SOCK_STREAM, IPPROTO_TCP);
#ifdef ZMQ_HAVE_WINDOWS
if (s == INVALID_SOCKET) {
wsa_error_to_errno ();
errno = wsa_error_to_errno (WSAGetLastError ());
return -1;
}
#else
......@@ -226,7 +226,7 @@ int zmq::tcp_connecter_t::open ()
errno = EINPROGRESS;
return -1;
}
wsa_error_to_errno ();
errno = wsa_error_to_errno (WSAGetLastError ());
#else
if (rc == -1 && errno == EINTR) {
errno = EINPROGRESS;
......
......@@ -156,7 +156,7 @@ int zmq::tcp_listener_t::set_address (const char *addr_)
s = open_socket (address.family (), SOCK_STREAM, IPPROTO_TCP);
#ifdef ZMQ_HAVE_WINDOWS
if (s == INVALID_SOCKET)
wsa_error_to_errno ();
errno = wsa_error_to_errno (WSAGetLastError ());
#endif
// IPv6 address family not supported, try automatic downgrade to IPv4.
......@@ -170,7 +170,7 @@ int zmq::tcp_listener_t::set_address (const char *addr_)
#ifdef ZMQ_HAVE_WINDOWS
if (s == INVALID_SOCKET) {
wsa_error_to_errno ();
errno = wsa_error_to_errno (WSAGetLastError ());
return -1;
}
// On Windows, preventing sockets to be inherited by child processes.
......@@ -203,7 +203,7 @@ int zmq::tcp_listener_t::set_address (const char *addr_)
rc = bind (s, address.addr (), address.addrlen ());
#ifdef ZMQ_HAVE_WINDOWS
if (rc == SOCKET_ERROR) {
wsa_error_to_errno ();
errno = wsa_error_to_errno (WSAGetLastError ());
return -1;
}
#else
......@@ -215,7 +215,7 @@ int zmq::tcp_listener_t::set_address (const char *addr_)
rc = listen (s, options.backlog);
#ifdef ZMQ_HAVE_WINDOWS
if (rc == SOCKET_ERROR) {
wsa_error_to_errno ();
errno = wsa_error_to_errno (WSAGetLastError ());
return -1;
}
#else
......
......@@ -853,17 +853,15 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
#if defined ZMQ_HAVE_WINDOWS
int rc = select (0, &inset, &outset, &errset, ptimeout);
if (unlikely (rc == SOCKET_ERROR)) {
zmq::wsa_error_to_errno ();
if (errno == ENOTSOCK)
return -1;
wsa_assert (false);
errno = zmq::wsa_error_to_errno (WSAGetLastError ());
wsa_assert (errno == ENOTSOCK);
return -1;
}
#else
int rc = select (maxfd + 1, &inset, &outset, &errset, ptimeout);
if (unlikely (rc == -1)) {
if (errno == EINTR || errno == EBADF)
return -1;
errno_assert (false);
errno_assert (errno == EINTR || errno == EBADF);
return -1;
}
#endif
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