From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 31FCF385736F; Thu, 4 Aug 2022 10:56:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 31FCF385736F Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: net.cc: convert wsock_errmap into a simple array of error codes X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/master X-Git-Oldrev: a8c1dd2ce08039e939dd1c57f02e5f1ed1593398 X-Git-Newrev: 70c7e8c1baaf5aa3a1e7327cd21463f4fa5b336b Message-Id: <20220804105637.31FCF385736F@sourceware.org> Date: Thu, 4 Aug 2022 10:56:37 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Aug 2022 10:56:37 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D70c7e8c1baa= f5aa3a1e7327cd21463f4fa5b336b commit 70c7e8c1baaf5aa3a1e7327cd21463f4fa5b336b Author: Corinna Vinschen Date: Thu Aug 4 11:45:58 2022 +0200 Cygwin: net.cc: convert wsock_errmap into a simple array of error codes =20 Avoid linear searches for error codes by converting wsock_errmap to a ordered array, indexed by WinSock error code (subtracted by WSABASEERR. =20 Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/net.cc | 134 +++++++++++++++++++++++++++++++----------------= ---- 1 file changed, 82 insertions(+), 52 deletions(-) diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index 83ea37f6e..8840d5ead 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -134,63 +134,93 @@ inet_makeaddr (int net, int lna) return in; } =20 -static const errmap_t wsock_errmap[] =3D { - {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[] =3D +{ + 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 */ }; =20 int find_winsock_errno (DWORD why) { - for (int i =3D 0; wsock_errmap[i].s !=3D NULL; ++i) - if (why =3D=3D wsock_errmap[i].w) - return wsock_errmap[i].e; + if (!why) + return 0; + if (why < WSABASEERR) + geterrno_from_win_error (why, EACCES); + + why -=3D WSABASEERR; + if (why < sizeof wsock_errmap / sizeof wsock_errmap[0]) + return wsock_errmap[why]; =20 return EACCES; }