2009-07-29 12:07:54 +02:00
|
|
|
/*
|
2014-01-02 12:00:57 +01:00
|
|
|
Copyright (c) 2007-2014 Contributors as noted in the AUTHORS file
|
2009-07-29 12:07:54 +02:00
|
|
|
|
|
|
|
This file is part of 0MQ.
|
|
|
|
|
|
|
|
0MQ is free software; you can redistribute it and/or modify it under
|
2010-10-30 15:08:28 +02:00
|
|
|
the terms of the GNU Lesser General Public License as published by
|
2009-07-29 12:07:54 +02:00
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
0MQ is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2010-10-30 15:08:28 +02:00
|
|
|
GNU Lesser General Public License for more details.
|
2009-07-29 12:07:54 +02:00
|
|
|
|
2010-10-30 15:08:28 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2009-07-29 12:07:54 +02:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "err.hpp"
|
|
|
|
#include "platform.hpp"
|
|
|
|
|
2010-10-16 16:05:34 +02:00
|
|
|
const char *zmq::errno_to_string (int errno_)
|
|
|
|
{
|
|
|
|
switch (errno_) {
|
|
|
|
#if defined ZMQ_HAVE_WINDOWS
|
|
|
|
case ENOTSUP:
|
|
|
|
return "Not supported";
|
|
|
|
case EPROTONOSUPPORT:
|
|
|
|
return "Protocol not supported";
|
|
|
|
case ENOBUFS:
|
|
|
|
return "No buffer space available";
|
|
|
|
case ENETDOWN:
|
|
|
|
return "Network is down";
|
|
|
|
case EADDRINUSE:
|
|
|
|
return "Address in use";
|
|
|
|
case EADDRNOTAVAIL:
|
|
|
|
return "Address not available";
|
|
|
|
case ECONNREFUSED:
|
|
|
|
return "Connection refused";
|
|
|
|
case EINPROGRESS:
|
|
|
|
return "Operation in progress";
|
|
|
|
#endif
|
|
|
|
case EFSM:
|
|
|
|
return "Operation cannot be accomplished in current state";
|
|
|
|
case ENOCOMPATPROTO:
|
|
|
|
return "The protocol is not compatible with the socket type";
|
|
|
|
case ETERM:
|
|
|
|
return "Context was terminated";
|
|
|
|
case EMTHREAD:
|
|
|
|
return "No thread available";
|
|
|
|
default:
|
|
|
|
#if defined _MSC_VER
|
|
|
|
#pragma warning (push)
|
|
|
|
#pragma warning (disable:4996)
|
|
|
|
#endif
|
|
|
|
return strerror (errno_);
|
|
|
|
#if defined _MSC_VER
|
|
|
|
#pragma warning (pop)
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-27 11:48:58 +02:00
|
|
|
void zmq::zmq_abort(const char *errmsg_)
|
|
|
|
{
|
|
|
|
#if defined ZMQ_HAVE_WINDOWS
|
|
|
|
|
|
|
|
// Raise STATUS_FATAL_APP_EXIT.
|
|
|
|
ULONG_PTR extra_info [1];
|
|
|
|
extra_info [0] = (ULONG_PTR) errmsg_;
|
|
|
|
RaiseException (0x40000015, EXCEPTION_NONCONTINUABLE, 1, extra_info);
|
|
|
|
#else
|
2012-08-27 16:05:51 -07:00
|
|
|
(void)errmsg_;
|
2011-10-27 11:48:58 +02:00
|
|
|
abort ();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-08-03 11:30:13 +02:00
|
|
|
#ifdef ZMQ_HAVE_WINDOWS
|
2009-07-29 12:07:54 +02:00
|
|
|
|
2009-08-03 11:30:13 +02:00
|
|
|
const char *zmq::wsa_error()
|
2009-07-29 12:07:54 +02:00
|
|
|
{
|
2011-05-08 09:03:49 +02:00
|
|
|
int no = WSAGetLastError ();
|
2009-07-29 12:07:54 +02:00
|
|
|
// TODO: This is not a generic way to handle this...
|
2011-05-08 09:03:49 +02:00
|
|
|
if (no == WSAEWOULDBLOCK)
|
2009-07-29 12:07:54 +02:00
|
|
|
return NULL;
|
|
|
|
|
2011-05-08 09:03:49 +02:00
|
|
|
return wsa_error_no (no);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *zmq::wsa_error_no (int no_)
|
|
|
|
{
|
2009-09-22 11:52:35 +02:00
|
|
|
// 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
|
|
|
|
// automatically (wsaError->HRESULT->string?).
|
2009-07-29 12:07:54 +02:00
|
|
|
return
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSABASEERR) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"No Error" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAEINTR) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Interrupted system call" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAEBADF) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Bad file number" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAEACCES) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Permission denied" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAEFAULT) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Bad address" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAEINVAL) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Invalid argument" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAEMFILE) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Too many open files" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAEWOULDBLOCK) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Operation would block" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAEINPROGRESS) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Operation now in progress" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAEALREADY) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Operation already in progress" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAENOTSOCK) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Socket operation on non-socket" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAEDESTADDRREQ) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Destination address required" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAEMSGSIZE) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Message too long" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAEPROTOTYPE) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Protocol wrong type for socket" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAENOPROTOOPT) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Bad protocol option" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAEPROTONOSUPPORT) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Protocol not supported" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAESOCKTNOSUPPORT) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Socket type not supported" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAEOPNOTSUPP) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Operation not supported on socket" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAEPFNOSUPPORT) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Protocol family not supported" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAEAFNOSUPPORT) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Address family not supported by protocol family" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAEADDRINUSE) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Address already in use" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAEADDRNOTAVAIL) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Can't assign requested address" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAENETDOWN) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Network is down" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAENETUNREACH) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Network is unreachable" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAENETRESET) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Net dropped connection or reset" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAECONNABORTED) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Software caused connection abort" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAECONNRESET) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Connection reset by peer" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAENOBUFS) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"No buffer space available" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAEISCONN) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Socket is already connected" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAENOTCONN) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Socket is not connected" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAESHUTDOWN) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Can't send after socket shutdown" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAETOOMANYREFS) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Too many references can't splice" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAETIMEDOUT) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Connection timed out" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAECONNREFUSED) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Connection refused" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAELOOP) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Too many levels of symbolic links" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAENAMETOOLONG) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"File name too long" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAEHOSTDOWN) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Host is down" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAEHOSTUNREACH) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"No Route to Host" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAENOTEMPTY) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Directory not empty" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAEPROCLIM) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Too many processes" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAEUSERS) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Too many users" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAEDQUOT) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Disc Quota Exceeded" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAESTALE) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Stale NFS file handle" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAEREMOTE) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Too many levels of remote in path" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSASYSNOTREADY) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Network SubSystem is unavailable" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAVERNOTSUPPORTED) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"WINSOCK DLL Version out of range" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSANOTINITIALISED) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Successful WSASTARTUP not yet performed" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSAHOST_NOT_FOUND) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Host not found" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSATRY_AGAIN) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Non-Authoritative Host not found" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSANO_RECOVERY) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Non-Recoverable errors: FORMERR REFUSED NOTIMP" :
|
2011-05-08 09:03:49 +02:00
|
|
|
(no_ == WSANO_DATA) ?
|
2009-07-29 12:07:54 +02:00
|
|
|
"Valid name no data record of requested" :
|
|
|
|
"error not defined";
|
|
|
|
}
|
2011-05-08 09:03:49 +02:00
|
|
|
|
2009-08-03 11:30:13 +02:00
|
|
|
void zmq::win_error (char *buffer_, size_t buffer_size_)
|
2009-07-29 12:07:54 +02:00
|
|
|
{
|
|
|
|
DWORD errcode = GetLastError ();
|
2013-02-19 16:49:23 +01:00
|
|
|
#if defined _WIN32_WCE
|
2012-03-14 19:12:28 +04:00
|
|
|
DWORD rc = FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM |
|
|
|
|
FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errcode, MAKELANGID(LANG_NEUTRAL,
|
|
|
|
SUBLANG_DEFAULT), (LPWSTR)buffer_, buffer_size_ / sizeof(wchar_t), NULL );
|
|
|
|
#else
|
2009-07-29 12:07:54 +02:00
|
|
|
DWORD rc = FormatMessageA (FORMAT_MESSAGE_FROM_SYSTEM |
|
|
|
|
FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errcode, MAKELANGID(LANG_NEUTRAL,
|
2011-05-15 13:12:09 +02:00
|
|
|
SUBLANG_DEFAULT), buffer_, (DWORD) buffer_size_, NULL );
|
2012-03-14 19:12:28 +04:00
|
|
|
#endif
|
2009-08-03 11:30:13 +02:00
|
|
|
zmq_assert (rc);
|
2009-07-29 12:07:54 +02:00
|
|
|
}
|
|
|
|
|
2012-05-27 16:10:19 +02:00
|
|
|
int zmq::wsa_error_to_errno (int errcode)
|
2009-10-01 13:48:04 +02:00
|
|
|
{
|
|
|
|
switch (errcode) {
|
2012-06-13 19:42:11 -04:00
|
|
|
// 10009 - File handle is not valid.
|
2009-10-01 13:48:04 +02:00
|
|
|
case WSAEBADF:
|
2012-05-27 16:10:19 +02:00
|
|
|
return EBADF;
|
2012-06-13 19:42:11 -04:00
|
|
|
// 10013 - Permission denied.
|
|
|
|
case WSAEACCES:
|
|
|
|
return EACCES;
|
|
|
|
// 10014 - Bad address.
|
|
|
|
case WSAEFAULT:
|
|
|
|
return EFAULT;
|
|
|
|
// 10022 - Invalid argument.
|
2009-10-01 13:48:04 +02:00
|
|
|
case WSAEINVAL:
|
2012-05-27 16:10:19 +02:00
|
|
|
return EINVAL;
|
2012-06-13 19:42:11 -04:00
|
|
|
// 10024 - Too many open files.
|
2009-10-01 13:48:04 +02:00
|
|
|
case WSAEMFILE:
|
2012-05-27 16:10:19 +02:00
|
|
|
return EMFILE;
|
2012-06-13 19:42:11 -04:00
|
|
|
// 10036 - Operation now in progress.
|
|
|
|
case WSAEINPROGRESS:
|
|
|
|
return EAGAIN;
|
|
|
|
// 10040 - Message too long.
|
|
|
|
case WSAEMSGSIZE:
|
|
|
|
return EMSGSIZE;
|
|
|
|
// 10043 - Protocol not supported.
|
2009-10-01 13:48:04 +02:00
|
|
|
case WSAEPROTONOSUPPORT:
|
2012-05-27 16:10:19 +02:00
|
|
|
return EPROTONOSUPPORT;
|
2012-06-13 19:42:11 -04:00
|
|
|
// 10047 - Address family not supported by protocol family.
|
|
|
|
case WSAEAFNOSUPPORT:
|
|
|
|
return EAFNOSUPPORT;
|
|
|
|
// 10048 - Address already in use.
|
2009-10-01 13:48:04 +02:00
|
|
|
case WSAEADDRINUSE:
|
2012-05-27 16:10:19 +02:00
|
|
|
return EADDRINUSE;
|
2012-06-13 19:42:11 -04:00
|
|
|
// 10049 - Cannot assign requested address.
|
2009-10-01 13:48:04 +02:00
|
|
|
case WSAEADDRNOTAVAIL:
|
2012-05-27 16:10:19 +02:00
|
|
|
return EADDRNOTAVAIL;
|
2012-06-13 19:42:11 -04:00
|
|
|
// 10050 - Network is down.
|
|
|
|
case WSAENETDOWN:
|
|
|
|
return ENETDOWN;
|
|
|
|
// 10051 - Network is unreachable.
|
|
|
|
case WSAENETUNREACH:
|
|
|
|
return ENETUNREACH;
|
|
|
|
// 10052 - Network dropped connection on reset.
|
|
|
|
case WSAENETRESET:
|
|
|
|
return ENETRESET;
|
|
|
|
// 10053 - Software caused connection abort.
|
|
|
|
case WSAECONNABORTED:
|
|
|
|
return ECONNABORTED;
|
|
|
|
// 10054 - Connection reset by peer.
|
|
|
|
case WSAECONNRESET:
|
|
|
|
return ECONNRESET;
|
|
|
|
// 10055 - No buffer space available.
|
|
|
|
case WSAENOBUFS:
|
|
|
|
return ENOBUFS;
|
|
|
|
// 10057 - Socket is not connected.
|
|
|
|
case WSAENOTCONN:
|
|
|
|
return ENOTCONN;
|
|
|
|
// 10060 - Connection timed out.
|
|
|
|
case WSAETIMEDOUT:
|
|
|
|
return ETIMEDOUT;
|
|
|
|
// 10061 - Connection refused.
|
|
|
|
case WSAECONNREFUSED:
|
|
|
|
return ECONNREFUSED;
|
|
|
|
// 10065 - No route to host.
|
|
|
|
case WSAEHOSTUNREACH:
|
|
|
|
return EHOSTUNREACH;
|
2009-10-01 13:48:04 +02:00
|
|
|
default:
|
|
|
|
wsa_assert (false);
|
|
|
|
}
|
2012-05-27 16:10:19 +02:00
|
|
|
// Not reachable
|
|
|
|
return 0;
|
2009-10-01 13:48:04 +02:00
|
|
|
}
|
|
|
|
|
2009-07-29 12:07:54 +02:00
|
|
|
#endif
|