diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2022-08-04 11:45:58 +0200 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2022-08-04 11:45:58 +0200 |
commit | 70c7e8c1baaf5aa3a1e7327cd21463f4fa5b336b (patch) | |
tree | d5d481db19d367b60e89e9df82f86b06a096039e | |
parent | a8c1dd2ce08039e939dd1c57f02e5f1ed1593398 (diff) | |
download | newlib-70c7e8c1baaf5aa3a1e7327cd21463f4fa5b336b.zip newlib-70c7e8c1baaf5aa3a1e7327cd21463f4fa5b336b.tar.gz newlib-70c7e8c1baaf5aa3a1e7327cd21463f4fa5b336b.tar.bz2 |
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>
-rw-r--r-- | winsup/cygwin/net.cc | 134 |
1 files changed, 82 insertions, 52 deletions
diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index 83ea37f..8840d5e 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -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; } |