Cygwin: net.cc: convert wsock_errmap into a simple array of error codes
Avoid linear searches for error codes by converting wsock_errmap to a ordered array, indexed by WinSock error code (subtracted by WSABASEERR. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
parent
a8c1dd2ce0
commit
70c7e8c1ba
|
@ -134,63 +134,93 @@ inet_makeaddr (int net, int lna)
|
|||
return in;
|
||||
}
|
||||
|
||||
static const errmap_t wsock_errmap[] = {
|
||||
{WSA_INVALID_HANDLE, "WSA_INVALID_HANDLE", EBADF},
|
||||
{WSA_NOT_ENOUGH_MEMORY, "WSA_NOT_ENOUGH_MEMORY", ENOMEM},
|
||||
{WSA_INVALID_PARAMETER, "WSA_INVALID_PARAMETER", EINVAL},
|
||||
{WSAEINTR, "WSAEINTR", EINTR},
|
||||
{WSAEWOULDBLOCK, "WSAEWOULDBLOCK", EWOULDBLOCK},
|
||||
{WSAEINPROGRESS, "WSAEINPROGRESS", EINPROGRESS},
|
||||
{WSAEALREADY, "WSAEALREADY", EALREADY},
|
||||
{WSAENOTSOCK, "WSAENOTSOCK", ENOTSOCK},
|
||||
{WSAEDESTADDRREQ, "WSAEDESTADDRREQ", EDESTADDRREQ},
|
||||
{WSAEMSGSIZE, "WSAEMSGSIZE", EMSGSIZE},
|
||||
{WSAEPROTOTYPE, "WSAEPROTOTYPE", EPROTOTYPE},
|
||||
{WSAENOPROTOOPT, "WSAENOPROTOOPT", ENOPROTOOPT},
|
||||
{WSAEPROTONOSUPPORT, "WSAEPROTONOSUPPORT", EPROTONOSUPPORT},
|
||||
{WSAESOCKTNOSUPPORT, "WSAESOCKTNOSUPPORT", ESOCKTNOSUPPORT},
|
||||
{WSAEOPNOTSUPP, "WSAEOPNOTSUPP", EOPNOTSUPP},
|
||||
{WSAEPFNOSUPPORT, "WSAEPFNOSUPPORT", EPFNOSUPPORT},
|
||||
{WSAEAFNOSUPPORT, "WSAEAFNOSUPPORT", EAFNOSUPPORT},
|
||||
{WSAEADDRINUSE, "WSAEADDRINUSE", EADDRINUSE},
|
||||
{WSAEADDRNOTAVAIL, "WSAEADDRNOTAVAIL", EADDRNOTAVAIL},
|
||||
{WSAENETDOWN, "WSAENETDOWN", ENETDOWN},
|
||||
{WSAENETUNREACH, "WSAENETUNREACH", ENETUNREACH},
|
||||
{WSAENETRESET, "WSAENETRESET", ENETRESET},
|
||||
{WSAECONNABORTED, "WSAECONNABORTED", ECONNABORTED},
|
||||
{WSAECONNRESET, "WSAECONNRESET", ECONNRESET},
|
||||
{WSAENOBUFS, "WSAENOBUFS", ENOBUFS},
|
||||
{WSAEISCONN, "WSAEISCONN", EISCONN},
|
||||
{WSAENOTCONN, "WSAENOTCONN", ENOTCONN},
|
||||
{WSAESHUTDOWN, "WSAESHUTDOWN", ESHUTDOWN},
|
||||
{WSAETOOMANYREFS, "WSAETOOMANYREFS", ETOOMANYREFS},
|
||||
{WSAETIMEDOUT, "WSAETIMEDOUT", ETIMEDOUT},
|
||||
{WSAECONNREFUSED, "WSAECONNREFUSED", ECONNREFUSED},
|
||||
{WSAELOOP, "WSAELOOP", ELOOP},
|
||||
{WSAENAMETOOLONG, "WSAENAMETOOLONG", ENAMETOOLONG},
|
||||
{WSAEHOSTDOWN, "WSAEHOSTDOWN", EHOSTDOWN},
|
||||
{WSAEHOSTUNREACH, "WSAEHOSTUNREACH", EHOSTUNREACH},
|
||||
{WSAENOTEMPTY, "WSAENOTEMPTY", ENOTEMPTY},
|
||||
{WSAEPROCLIM, "WSAEPROCLIM", EPROCLIM},
|
||||
{WSAEUSERS, "WSAEUSERS", EUSERS},
|
||||
{WSAEDQUOT, "WSAEDQUOT", EDQUOT},
|
||||
{WSAESTALE, "WSAESTALE", ESTALE},
|
||||
{WSAEREMOTE, "WSAEREMOTE", EREMOTE},
|
||||
{WSAEINVAL, "WSAEINVAL", EINVAL},
|
||||
{WSAEFAULT, "WSAEFAULT", EFAULT},
|
||||
{WSAEBADF, "WSAEBADF", EBADF},
|
||||
{WSAEACCES, "WSAEACCES", EACCES},
|
||||
{WSAEMFILE, "WSAEMFILE", EMFILE},
|
||||
{0, "NOERROR", 0},
|
||||
{0, NULL, 0}
|
||||
static const int wsock_errmap[] =
|
||||
{
|
||||
0, /* WSABASEERR (10000) */
|
||||
0, /* 10001 */
|
||||
0, /* 10002 */
|
||||
0, /* 10003 */
|
||||
EINTR, /* WSAEINTR */
|
||||
0, /* 10005 */
|
||||
0, /* 10006 */
|
||||
0, /* 10007 */
|
||||
0, /* 10008 */
|
||||
EBADF, /* WSAEBADF */
|
||||
0, /* 10010 */
|
||||
0, /* 10011 */
|
||||
0, /* 10012 */
|
||||
EACCES, /* WSAEACCES */
|
||||
EFAULT, /* WSAEFAULT */
|
||||
0, /* 10015 */
|
||||
0, /* 10016 */
|
||||
0, /* 10017 */
|
||||
0, /* 10018 */
|
||||
0, /* 10019 */
|
||||
0, /* 10020 */
|
||||
0, /* 10021 */
|
||||
EINVAL, /* WSAEINVAL */
|
||||
0, /* 10023 */
|
||||
EMFILE, /* WSAEMFILE */
|
||||
0, /* 10025 */
|
||||
0, /* 10026 */
|
||||
0, /* 10027 */
|
||||
0, /* 10028 */
|
||||
0, /* 10029 */
|
||||
0, /* 10030 */
|
||||
0, /* 10031 */
|
||||
0, /* 10032 */
|
||||
0, /* 10033 */
|
||||
0, /* 10034 */
|
||||
EWOULDBLOCK, /* WSAEWOULDBLOCK */
|
||||
EINPROGRESS, /* WSAEINPROGRESS */
|
||||
EALREADY, /* WSAEALREADY */
|
||||
ENOTSOCK, /* WSAENOTSOCK */
|
||||
EDESTADDRREQ, /* WSAEDESTADDRREQ */
|
||||
EMSGSIZE, /* WSAEMSGSIZE */
|
||||
EPROTOTYPE, /* WSAEPROTOTYPE */
|
||||
ENOPROTOOPT, /* WSAENOPROTOOPT */
|
||||
EPROTONOSUPPORT, /* WSAEPROTONOSUPPORT */
|
||||
ESOCKTNOSUPPORT, /* WSAESOCKTNOSUPPORT */
|
||||
EOPNOTSUPP, /* WSAEOPNOTSUPP */
|
||||
EPFNOSUPPORT, /* WSAEPFNOSUPPORT */
|
||||
EAFNOSUPPORT, /* WSAEAFNOSUPPORT */
|
||||
EADDRINUSE, /* WSAEADDRINUSE */
|
||||
EADDRNOTAVAIL, /* WSAEADDRNOTAVAIL */
|
||||
ENETDOWN, /* WSAENETDOWN */
|
||||
ENETUNREACH, /* WSAENETUNREACH */
|
||||
ENETRESET, /* WSAENETRESET */
|
||||
ECONNABORTED, /* WSAECONNABORTED */
|
||||
ECONNRESET, /* WSAECONNRESET */
|
||||
ENOBUFS, /* WSAENOBUFS */
|
||||
EISCONN, /* WSAEISCONN */
|
||||
ENOTCONN, /* WSAENOTCONN */
|
||||
ESHUTDOWN, /* WSAESHUTDOWN */
|
||||
ETOOMANYREFS, /* WSAETOOMANYREFS */
|
||||
ETIMEDOUT, /* WSAETIMEDOUT */
|
||||
ECONNREFUSED, /* WSAECONNREFUSED */
|
||||
ELOOP, /* WSAELOOP */
|
||||
ENAMETOOLONG, /* WSAENAMETOOLONG */
|
||||
EHOSTDOWN, /* WSAEHOSTDOWN */
|
||||
EHOSTUNREACH, /* WSAEHOSTUNREACH */
|
||||
ENOTEMPTY, /* WSAENOTEMPTY */
|
||||
EPROCLIM, /* WSAEPROCLIM */
|
||||
EUSERS, /* WSAEUSERS */
|
||||
EDQUOT, /* WSAEDQUOT */
|
||||
ESTALE, /* WSAESTALE */
|
||||
EREMOTE, /* WSAEREMOTE */
|
||||
};
|
||||
|
||||
int
|
||||
find_winsock_errno (DWORD why)
|
||||
{
|
||||
for (int i = 0; wsock_errmap[i].s != NULL; ++i)
|
||||
if (why == wsock_errmap[i].w)
|
||||
return wsock_errmap[i].e;
|
||||
if (!why)
|
||||
return 0;
|
||||
if (why < WSABASEERR)
|
||||
geterrno_from_win_error (why, EACCES);
|
||||
|
||||
why -= WSABASEERR;
|
||||
if (why < sizeof wsock_errmap / sizeof wsock_errmap[0])
|
||||
return wsock_errmap[why];
|
||||
|
||||
return EACCES;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue