mirror of
https://github.com/zeromq/libzmq.git
synced 2025-03-09 15:26:04 +00:00
Async connect doesn't fail on EWSANETDOWN
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
This commit is contained in:
parent
da1ef4d268
commit
49387874ef
112
src/err.cpp
112
src/err.cpp
@ -66,119 +66,125 @@ const char *zmq::errno_to_string (int errno_)
|
|||||||
|
|
||||||
const char *zmq::wsa_error()
|
const char *zmq::wsa_error()
|
||||||
{
|
{
|
||||||
int errcode = WSAGetLastError ();
|
int no = WSAGetLastError ();
|
||||||
// TODO: This is not a generic way to handle this...
|
// TODO: This is not a generic way to handle this...
|
||||||
if (errcode == WSAEWOULDBLOCK)
|
if (no == WSAEWOULDBLOCK)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
return wsa_error_no (no);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *zmq::wsa_error_no (int no_)
|
||||||
|
{
|
||||||
// TODO: It seems that list of Windows socket errors is longer than this.
|
// TODO: It seems that list of Windows socket errors is longer than this.
|
||||||
// Investigate whether there's a way to convert it into the string
|
// Investigate whether there's a way to convert it into the string
|
||||||
// automatically (wsaError->HRESULT->string?).
|
// automatically (wsaError->HRESULT->string?).
|
||||||
return
|
return
|
||||||
(errcode == WSABASEERR) ?
|
(no_ == WSABASEERR) ?
|
||||||
"No Error" :
|
"No Error" :
|
||||||
(errcode == WSAEINTR) ?
|
(no_ == WSAEINTR) ?
|
||||||
"Interrupted system call" :
|
"Interrupted system call" :
|
||||||
(errcode == WSAEBADF) ?
|
(no_ == WSAEBADF) ?
|
||||||
"Bad file number" :
|
"Bad file number" :
|
||||||
(errcode == WSAEACCES) ?
|
(no_ == WSAEACCES) ?
|
||||||
"Permission denied" :
|
"Permission denied" :
|
||||||
(errcode == WSAEFAULT) ?
|
(no_ == WSAEFAULT) ?
|
||||||
"Bad address" :
|
"Bad address" :
|
||||||
(errcode == WSAEINVAL) ?
|
(no_ == WSAEINVAL) ?
|
||||||
"Invalid argument" :
|
"Invalid argument" :
|
||||||
(errcode == WSAEMFILE) ?
|
(no_ == WSAEMFILE) ?
|
||||||
"Too many open files" :
|
"Too many open files" :
|
||||||
(errcode == WSAEWOULDBLOCK) ?
|
(no_ == WSAEWOULDBLOCK) ?
|
||||||
"Operation would block" :
|
"Operation would block" :
|
||||||
(errcode == WSAEINPROGRESS) ?
|
(no_ == WSAEINPROGRESS) ?
|
||||||
"Operation now in progress" :
|
"Operation now in progress" :
|
||||||
(errcode == WSAEALREADY) ?
|
(no_ == WSAEALREADY) ?
|
||||||
"Operation already in progress" :
|
"Operation already in progress" :
|
||||||
(errcode == WSAENOTSOCK) ?
|
(no_ == WSAENOTSOCK) ?
|
||||||
"Socket operation on non-socket" :
|
"Socket operation on non-socket" :
|
||||||
(errcode == WSAEDESTADDRREQ) ?
|
(no_ == WSAEDESTADDRREQ) ?
|
||||||
"Destination address required" :
|
"Destination address required" :
|
||||||
(errcode == WSAEMSGSIZE) ?
|
(no_ == WSAEMSGSIZE) ?
|
||||||
"Message too long" :
|
"Message too long" :
|
||||||
(errcode == WSAEPROTOTYPE) ?
|
(no_ == WSAEPROTOTYPE) ?
|
||||||
"Protocol wrong type for socket" :
|
"Protocol wrong type for socket" :
|
||||||
(errcode == WSAENOPROTOOPT) ?
|
(no_ == WSAENOPROTOOPT) ?
|
||||||
"Bad protocol option" :
|
"Bad protocol option" :
|
||||||
(errcode == WSAEPROTONOSUPPORT) ?
|
(no_ == WSAEPROTONOSUPPORT) ?
|
||||||
"Protocol not supported" :
|
"Protocol not supported" :
|
||||||
(errcode == WSAESOCKTNOSUPPORT) ?
|
(no_ == WSAESOCKTNOSUPPORT) ?
|
||||||
"Socket type not supported" :
|
"Socket type not supported" :
|
||||||
(errcode == WSAEOPNOTSUPP) ?
|
(no_ == WSAEOPNOTSUPP) ?
|
||||||
"Operation not supported on socket" :
|
"Operation not supported on socket" :
|
||||||
(errcode == WSAEPFNOSUPPORT) ?
|
(no_ == WSAEPFNOSUPPORT) ?
|
||||||
"Protocol family not supported" :
|
"Protocol family not supported" :
|
||||||
(errcode == WSAEAFNOSUPPORT) ?
|
(no_ == WSAEAFNOSUPPORT) ?
|
||||||
"Address family not supported by protocol family" :
|
"Address family not supported by protocol family" :
|
||||||
(errcode == WSAEADDRINUSE) ?
|
(no_ == WSAEADDRINUSE) ?
|
||||||
"Address already in use" :
|
"Address already in use" :
|
||||||
(errcode == WSAEADDRNOTAVAIL) ?
|
(no_ == WSAEADDRNOTAVAIL) ?
|
||||||
"Can't assign requested address" :
|
"Can't assign requested address" :
|
||||||
(errcode == WSAENETDOWN) ?
|
(no_ == WSAENETDOWN) ?
|
||||||
"Network is down" :
|
"Network is down" :
|
||||||
(errcode == WSAENETUNREACH) ?
|
(no_ == WSAENETUNREACH) ?
|
||||||
"Network is unreachable" :
|
"Network is unreachable" :
|
||||||
(errcode == WSAENETRESET) ?
|
(no_ == WSAENETRESET) ?
|
||||||
"Net dropped connection or reset" :
|
"Net dropped connection or reset" :
|
||||||
(errcode == WSAECONNABORTED) ?
|
(no_ == WSAECONNABORTED) ?
|
||||||
"Software caused connection abort" :
|
"Software caused connection abort" :
|
||||||
(errcode == WSAECONNRESET) ?
|
(no_ == WSAECONNRESET) ?
|
||||||
"Connection reset by peer" :
|
"Connection reset by peer" :
|
||||||
(errcode == WSAENOBUFS) ?
|
(no_ == WSAENOBUFS) ?
|
||||||
"No buffer space available" :
|
"No buffer space available" :
|
||||||
(errcode == WSAEISCONN) ?
|
(no_ == WSAEISCONN) ?
|
||||||
"Socket is already connected" :
|
"Socket is already connected" :
|
||||||
(errcode == WSAENOTCONN) ?
|
(no_ == WSAENOTCONN) ?
|
||||||
"Socket is not connected" :
|
"Socket is not connected" :
|
||||||
(errcode == WSAESHUTDOWN) ?
|
(no_ == WSAESHUTDOWN) ?
|
||||||
"Can't send after socket shutdown" :
|
"Can't send after socket shutdown" :
|
||||||
(errcode == WSAETOOMANYREFS) ?
|
(no_ == WSAETOOMANYREFS) ?
|
||||||
"Too many references can't splice" :
|
"Too many references can't splice" :
|
||||||
(errcode == WSAETIMEDOUT) ?
|
(no_ == WSAETIMEDOUT) ?
|
||||||
"Connection timed out" :
|
"Connection timed out" :
|
||||||
(errcode == WSAECONNREFUSED) ?
|
(no_ == WSAECONNREFUSED) ?
|
||||||
"Connection refused" :
|
"Connection refused" :
|
||||||
(errcode == WSAELOOP) ?
|
(no_ == WSAELOOP) ?
|
||||||
"Too many levels of symbolic links" :
|
"Too many levels of symbolic links" :
|
||||||
(errcode == WSAENAMETOOLONG) ?
|
(no_ == WSAENAMETOOLONG) ?
|
||||||
"File name too long" :
|
"File name too long" :
|
||||||
(errcode == WSAEHOSTDOWN) ?
|
(no_ == WSAEHOSTDOWN) ?
|
||||||
"Host is down" :
|
"Host is down" :
|
||||||
(errcode == WSAEHOSTUNREACH) ?
|
(no_ == WSAEHOSTUNREACH) ?
|
||||||
"No Route to Host" :
|
"No Route to Host" :
|
||||||
(errcode == WSAENOTEMPTY) ?
|
(no_ == WSAENOTEMPTY) ?
|
||||||
"Directory not empty" :
|
"Directory not empty" :
|
||||||
(errcode == WSAEPROCLIM) ?
|
(no_ == WSAEPROCLIM) ?
|
||||||
"Too many processes" :
|
"Too many processes" :
|
||||||
(errcode == WSAEUSERS) ?
|
(no_ == WSAEUSERS) ?
|
||||||
"Too many users" :
|
"Too many users" :
|
||||||
(errcode == WSAEDQUOT) ?
|
(no_ == WSAEDQUOT) ?
|
||||||
"Disc Quota Exceeded" :
|
"Disc Quota Exceeded" :
|
||||||
(errcode == WSAESTALE) ?
|
(no_ == WSAESTALE) ?
|
||||||
"Stale NFS file handle" :
|
"Stale NFS file handle" :
|
||||||
(errcode == WSAEREMOTE) ?
|
(no_ == WSAEREMOTE) ?
|
||||||
"Too many levels of remote in path" :
|
"Too many levels of remote in path" :
|
||||||
(errcode == WSASYSNOTREADY) ?
|
(no_ == WSASYSNOTREADY) ?
|
||||||
"Network SubSystem is unavailable" :
|
"Network SubSystem is unavailable" :
|
||||||
(errcode == WSAVERNOTSUPPORTED) ?
|
(no_ == WSAVERNOTSUPPORTED) ?
|
||||||
"WINSOCK DLL Version out of range" :
|
"WINSOCK DLL Version out of range" :
|
||||||
(errcode == WSANOTINITIALISED) ?
|
(no_ == WSANOTINITIALISED) ?
|
||||||
"Successful WSASTARTUP not yet performed" :
|
"Successful WSASTARTUP not yet performed" :
|
||||||
(errcode == WSAHOST_NOT_FOUND) ?
|
(no_ == WSAHOST_NOT_FOUND) ?
|
||||||
"Host not found" :
|
"Host not found" :
|
||||||
(errcode == WSATRY_AGAIN) ?
|
(no_ == WSATRY_AGAIN) ?
|
||||||
"Non-Authoritative Host not found" :
|
"Non-Authoritative Host not found" :
|
||||||
(errcode == WSANO_RECOVERY) ?
|
(no_ == WSANO_RECOVERY) ?
|
||||||
"Non-Recoverable errors: FORMERR REFUSED NOTIMP" :
|
"Non-Recoverable errors: FORMERR REFUSED NOTIMP" :
|
||||||
(errcode == WSANO_DATA) ?
|
(no_ == WSANO_DATA) ?
|
||||||
"Valid name no data record of requested" :
|
"Valid name no data record of requested" :
|
||||||
"error not defined";
|
"error not defined";
|
||||||
}
|
}
|
||||||
|
|
||||||
void zmq::win_error (char *buffer_, size_t buffer_size_)
|
void zmq::win_error (char *buffer_, size_t buffer_size_)
|
||||||
{
|
{
|
||||||
DWORD errcode = GetLastError ();
|
DWORD errcode = GetLastError ();
|
||||||
|
12
src/err.hpp
12
src/err.hpp
@ -49,6 +49,7 @@ namespace zmq
|
|||||||
namespace zmq
|
namespace zmq
|
||||||
{
|
{
|
||||||
const char *wsa_error ();
|
const char *wsa_error ();
|
||||||
|
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 ();
|
void wsa_error_to_errno ();
|
||||||
}
|
}
|
||||||
@ -66,6 +67,17 @@ namespace zmq
|
|||||||
}\
|
}\
|
||||||
} while (false)
|
} while (false)
|
||||||
|
|
||||||
|
// Provides convenient way to assert on WSA-style errors on Windows.
|
||||||
|
#define wsa_assert_no(no) \
|
||||||
|
do {\
|
||||||
|
const char *errstr = zmq::wsa_error_no (no);\
|
||||||
|
if (errstr != NULL) {\
|
||||||
|
fprintf (stderr, "Assertion failed: %s (%s:%d)\n", errstr, \
|
||||||
|
__FILE__, __LINE__);\
|
||||||
|
abort ();\
|
||||||
|
}\
|
||||||
|
} while (false)
|
||||||
|
|
||||||
// Provides convenient way to check GetLastError-style errors on Windows.
|
// Provides convenient way to check GetLastError-style errors on Windows.
|
||||||
#define win_assert(x) \
|
#define win_assert(x) \
|
||||||
do {\
|
do {\
|
||||||
|
@ -116,12 +116,12 @@ zmq::fd_t zmq::tcp_connecter_t::connect ()
|
|||||||
|
|
||||||
// Assert that the error was caused by the networking problems
|
// Assert that the error was caused by the networking problems
|
||||||
// rather than 0MQ bug.
|
// rather than 0MQ bug.
|
||||||
errno = err;
|
if (err == WSAECONNREFUSED || err == WSAETIMEDOUT ||
|
||||||
errno_assert (errno == WSAECONNREFUSED || errno == WSAETIMEDOUT ||
|
err == WSAECONNABORTED || err == WSAEHOSTUNREACH ||
|
||||||
errno == WSAECONNABORTED || errno == WSAEHOSTUNREACH ||
|
err == WSAENETUNREACH || err == WSAENETDOWN)
|
||||||
errno == WSAENETUNREACH);
|
return retired_fd;
|
||||||
|
|
||||||
return retired_fd;
|
wsa_assert_no (err);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the newly connected socket.
|
// Return the newly connected socket.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user