public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Cygwin: net.cc: convert wsock_errmap into a simple array of error codes
@ 2022-08-04 10:56 Corinna Vinschen
  0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2022-08-04 10:56 UTC (permalink / raw)
  To: cygwin-cvs

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=70c7e8c1baaf5aa3a1e7327cd21463f4fa5b336b

commit 70c7e8c1baaf5aa3a1e7327cd21463f4fa5b336b
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Thu Aug 4 11:45:58 2022 +0200

    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>

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;
 }
 
-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;
 }


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-08-04 10:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-04 10:56 [newlib-cygwin] Cygwin: net.cc: convert wsock_errmap into a simple array of error codes Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).