Commit 003ae1bf authored by Constantin Rack's avatar Constantin Rack

Merge pull request #1520 from reza-ebrahimi/master

remove unnecessary multiple WSAGetLastError() calls
parents 6d217aa9 d7b74d1f
...@@ -89,12 +89,12 @@ void zmq::zmq_abort(const char *errmsg_) ...@@ -89,12 +89,12 @@ void zmq::zmq_abort(const char *errmsg_)
const char *zmq::wsa_error() const char *zmq::wsa_error()
{ {
int no = WSAGetLastError (); const int lastError = WSAGetLastError();
// TODO: This is not a generic way to handle this... // TODO: This is not a generic way to handle this...
if (no == WSAEWOULDBLOCK) if (lastError == WSAEWOULDBLOCK)
return NULL; return NULL;
return wsa_error_no (no); return wsa_error_no (lastError);
} }
const char *zmq::wsa_error_no (int no_) const char *zmq::wsa_error_no (int no_)
......
...@@ -132,10 +132,11 @@ int zmq::get_peer_ip_address (fd_t sockfd_, std::string &ip_addr_) ...@@ -132,10 +132,11 @@ int zmq::get_peer_ip_address (fd_t sockfd_, std::string &ip_addr_)
rc = getpeername (sockfd_, (struct sockaddr*) &ss, &addrlen); rc = getpeername (sockfd_, (struct sockaddr*) &ss, &addrlen);
#ifdef ZMQ_HAVE_WINDOWS #ifdef ZMQ_HAVE_WINDOWS
if (rc == SOCKET_ERROR) { if (rc == SOCKET_ERROR) {
wsa_assert (WSAGetLastError () != WSANOTINITIALISED && const int lastError = WSAGetLastError();
WSAGetLastError () != WSAEFAULT && wsa_assert (lastError != WSANOTINITIALISED &&
WSAGetLastError () != WSAEINPROGRESS && lastError != WSAEFAULT &&
WSAGetLastError () != WSAENOTSOCK); lastError != WSAEINPROGRESS &&
lastError != WSAENOTSOCK);
return 0; return 0;
} }
#else #else
......
...@@ -368,11 +368,11 @@ int zmq::socks_connecter_t::connect_to_proxy () ...@@ -368,11 +368,11 @@ int zmq::socks_connecter_t::connect_to_proxy ()
// Translate error codes indicating asynchronous connect has been // Translate error codes indicating asynchronous connect has been
// launched to a uniform EINPROGRESS. // launched to a uniform EINPROGRESS.
#ifdef ZMQ_HAVE_WINDOWS #ifdef ZMQ_HAVE_WINDOWS
const int error_code = WSAGetLastError (); const int lastError = WSAGetLastError();
if (error_code == WSAEINPROGRESS || error_code == WSAEWOULDBLOCK) if (lastError == WSAEINPROGRESS || lastError == WSAEWOULDBLOCK)
errno = EINPROGRESS; errno = EINPROGRESS;
else { else {
errno = wsa_error_to_errno (error_code); errno = wsa_error_to_errno (lastError);
close (); close ();
} }
#else #else
......
...@@ -178,22 +178,24 @@ void zmq::tune_tcp_retransmit_timeout (fd_t sockfd_, int timeout_) ...@@ -178,22 +178,24 @@ void zmq::tune_tcp_retransmit_timeout (fd_t sockfd_, int timeout_)
// If not a single byte can be written to the socket in non-blocking mode // If not a single byte can be written to the socket in non-blocking mode
// we'll get an error (this may happen during the speculative write). // we'll get an error (this may happen during the speculative write).
if (nbytes == SOCKET_ERROR && WSAGetLastError () == WSAEWOULDBLOCK) const int lastError = WSAGetLastError();
if (nbytes == SOCKET_ERROR && lastError == WSAEWOULDBLOCK)
return 0; return 0;
// Signalise peer failure. // Signalise peer failure.
if (nbytes == SOCKET_ERROR && ( if (nbytes == SOCKET_ERROR && (
WSAGetLastError () == WSAENETDOWN || lastError == WSAENETDOWN ||
WSAGetLastError () == WSAENETRESET || lastError == WSAENETRESET ||
WSAGetLastError () == WSAEHOSTUNREACH || lastError == WSAEHOSTUNREACH ||
WSAGetLastError () == WSAECONNABORTED || lastError == WSAECONNABORTED ||
WSAGetLastError () == WSAETIMEDOUT || lastError == WSAETIMEDOUT ||
WSAGetLastError () == WSAECONNRESET)) lastError == WSAECONNRESET
))
return -1; return -1;
// Circumvent a Windows bug; see https://support.microsoft.com/en-us/kb/201213 // Circumvent a Windows bug; see https://support.microsoft.com/en-us/kb/201213
// and https://zeromq.jira.com/browse/LIBZMQ-195 // and https://zeromq.jira.com/browse/LIBZMQ-195
if (nbytes == SOCKET_ERROR && WSAGetLastError() == WSAENOBUFS) if (nbytes == SOCKET_ERROR && lastError == WSAENOBUFS)
return 0; return 0;
wsa_assert (nbytes != SOCKET_ERROR); wsa_assert (nbytes != SOCKET_ERROR);
...@@ -238,21 +240,23 @@ int zmq::tcp_read (fd_t s_, void *data_, size_t size_) ...@@ -238,21 +240,23 @@ int zmq::tcp_read (fd_t s_, void *data_, size_t size_)
// If not a single byte can be read from the socket in non-blocking mode // If not a single byte can be read from the socket in non-blocking mode
// we'll get an error (this may happen during the speculative read). // we'll get an error (this may happen during the speculative read).
if (rc == SOCKET_ERROR) { if (rc == SOCKET_ERROR) {
if (WSAGetLastError () == WSAEWOULDBLOCK) const int lastError = WSAGetLastError();
if (lastError == WSAEWOULDBLOCK) {
errno = EAGAIN; errno = EAGAIN;
}
else { else {
wsa_assert (WSAGetLastError () == WSAENETDOWN wsa_assert (lastError == WSAENETDOWN ||
|| WSAGetLastError () == WSAENETRESET lastError == WSAENETRESET ||
|| WSAGetLastError () == WSAECONNABORTED lastError == WSAECONNABORTED ||
|| WSAGetLastError () == WSAETIMEDOUT lastError == WSAETIMEDOUT ||
|| WSAGetLastError () == WSAECONNRESET lastError == WSAECONNRESET ||
|| WSAGetLastError () == WSAECONNREFUSED lastError == WSAECONNREFUSED ||
|| WSAGetLastError () == WSAENOTCONN); lastError == WSAENOTCONN);
errno = wsa_error_to_errno (WSAGetLastError ()); errno = wsa_error_to_errno (lastError);
} }
} }
return rc == SOCKET_ERROR? -1: rc; return rc == SOCKET_ERROR ? -1 : rc;
#else #else
......
...@@ -319,11 +319,11 @@ int zmq::tcp_connecter_t::open () ...@@ -319,11 +319,11 @@ int zmq::tcp_connecter_t::open ()
// Translate error codes indicating asynchronous connect has been // Translate error codes indicating asynchronous connect has been
// launched to a uniform EINPROGRESS. // launched to a uniform EINPROGRESS.
#ifdef ZMQ_HAVE_WINDOWS #ifdef ZMQ_HAVE_WINDOWS
const int error_code = WSAGetLastError (); const int lastError = WSAGetLastError();
if (error_code == WSAEINPROGRESS || error_code == WSAEWOULDBLOCK) if (lastError == WSAEINPROGRESS || lastError == WSAEWOULDBLOCK)
errno = EINPROGRESS; errno = EINPROGRESS;
else else
errno = wsa_error_to_errno (error_code); errno = wsa_error_to_errno (lastError);
#else #else
if (errno == EINTR) if (errno == EINTR)
errno = EINPROGRESS; errno = EINPROGRESS;
......
...@@ -278,10 +278,11 @@ zmq::fd_t zmq::tcp_listener_t::accept () ...@@ -278,10 +278,11 @@ zmq::fd_t zmq::tcp_listener_t::accept ()
#ifdef ZMQ_HAVE_WINDOWS #ifdef ZMQ_HAVE_WINDOWS
if (sock == INVALID_SOCKET) { if (sock == INVALID_SOCKET) {
wsa_assert (WSAGetLastError () == WSAEWOULDBLOCK || const int lastError = WSAGetLastError();
WSAGetLastError () == WSAECONNRESET || wsa_assert (lastError == WSAEWOULDBLOCK ||
WSAGetLastError () == WSAEMFILE || lastError == WSAECONNRESET ||
WSAGetLastError () == WSAENOBUFS); lastError == WSAEMFILE ||
lastError == WSAENOBUFS);
return retired_fd; return retired_fd;
} }
#if !defined _WIN32_WCE #if !defined _WIN32_WCE
......
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