]> granicus.if.org Git - postgresql/commitdiff
Improve TranslateSocketError() to handle more Windows error codes.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 21 Apr 2016 20:58:47 +0000 (16:58 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 21 Apr 2016 20:58:47 +0000 (16:58 -0400)
The coverage was rather lean for cases that bind() or listen() might
return.  Add entries for everything that there's a direct equivalent
for in the set of Unix errnos that elog.c has heard of.

src/backend/port/win32/socket.c
src/include/port/win32.h

index 56a13e5894be18fadd491bb2d8260267338496b6..5d8fb7fc91d30ad711e6a09960b4aac636e03ad7 100644 (file)
@@ -44,23 +44,38 @@ int                 pgwin32_noblock = 0;
 
 /*
  * Convert the last socket error code into errno
+ *
+ * Note: where there is a direct correspondence between a WSAxxx error code
+ * and a Berkeley error symbol, this mapping is actually a no-op, because
+ * in win32.h we redefine the network-related Berkeley error symbols to have
+ * the values of their WSAxxx counterparts.  The point of the switch is
+ * mostly to translate near-miss error codes into something that's sensible
+ * in the Berkeley universe.
  */
 static void
 TranslateSocketError(void)
 {
        switch (WSAGetLastError())
        {
-               case WSANOTINITIALISED:
-               case WSAENETDOWN:
-               case WSAEINPROGRESS:
                case WSAEINVAL:
-               case WSAESOCKTNOSUPPORT:
-               case WSAEFAULT:
+               case WSANOTINITIALISED:
                case WSAEINVALIDPROVIDER:
                case WSAEINVALIDPROCTABLE:
-               case WSAEMSGSIZE:
+               case WSAEDESTADDRREQ:
                        errno = EINVAL;
                        break;
+               case WSAEINPROGRESS:
+                       errno = EINPROGRESS;
+                       break;
+               case WSAEFAULT:
+                       errno = EFAULT;
+                       break;
+               case WSAEISCONN:
+                       errno = EISCONN;
+                       break;
+               case WSAEMSGSIZE:
+                       errno = EMSGSIZE;
+                       break;
                case WSAEAFNOSUPPORT:
                        errno = EAFNOSUPPORT;
                        break;
@@ -72,16 +87,23 @@ TranslateSocketError(void)
                        break;
                case WSAEPROTONOSUPPORT:
                case WSAEPROTOTYPE:
+               case WSAESOCKTNOSUPPORT:
                        errno = EPROTONOSUPPORT;
                        break;
+               case WSAECONNABORTED:
+                       errno = ECONNABORTED;
+                       break;
                case WSAECONNREFUSED:
                        errno = ECONNREFUSED;
                        break;
+               case WSAECONNRESET:
+                       errno = ECONNRESET;
+                       break;
                case WSAEINTR:
                        errno = EINTR;
                        break;
                case WSAENOTSOCK:
-                       errno = EBADFD;
+                       errno = ENOTSOCK;
                        break;
                case WSAEOPNOTSUPP:
                        errno = EOPNOTSUPP;
@@ -92,13 +114,24 @@ TranslateSocketError(void)
                case WSAEACCES:
                        errno = EACCES;
                        break;
-               case WSAENOTCONN:
+               case WSAEADDRINUSE:
+                       errno = EADDRINUSE;
+                       break;
+               case WSAEADDRNOTAVAIL:
+                       errno = EADDRNOTAVAIL;
+                       break;
+               case WSAEHOSTUNREACH:
+               case WSAEHOSTDOWN:
+               case WSAHOST_NOT_FOUND:
+               case WSAENETDOWN:
+               case WSAENETUNREACH:
                case WSAENETRESET:
-               case WSAECONNRESET:
+                       errno = EHOSTUNREACH;
+                       break;
+               case WSAENOTCONN:
                case WSAESHUTDOWN:
-               case WSAECONNABORTED:
                case WSAEDISCON:
-                       errno = ECONNREFUSED;           /* ENOTCONN? */
+                       errno = ENOTCONN;
                        break;
                default:
                        ereport(NOTICE,
index c9390d11247096598b2dbc36fb3c0d38348fe754..bd2ad99c113cd842884dc96c5c9ca1033b214020 100644 (file)
@@ -285,20 +285,32 @@ typedef int pid_t;
 #define EAFNOSUPPORT WSAEAFNOSUPPORT
 #undef EWOULDBLOCK
 #define EWOULDBLOCK WSAEWOULDBLOCK
+#undef ECONNABORTED
+#define ECONNABORTED WSAECONNABORTED
 #undef ECONNRESET
 #define ECONNRESET WSAECONNRESET
 #undef EINPROGRESS
 #define EINPROGRESS WSAEINPROGRESS
+#undef EISCONN
+#define EISCONN WSAEISCONN
 #undef ENOBUFS
 #define ENOBUFS WSAENOBUFS
 #undef EPROTONOSUPPORT
 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
 #undef ECONNREFUSED
 #define ECONNREFUSED WSAECONNREFUSED
-#undef EBADFD
-#define EBADFD WSAENOTSOCK
+#undef ENOTSOCK
+#define ENOTSOCK WSAENOTSOCK
 #undef EOPNOTSUPP
 #define EOPNOTSUPP WSAEOPNOTSUPP
+#undef EADDRINUSE
+#define EADDRINUSE WSAEADDRINUSE
+#undef EADDRNOTAVAIL
+#define EADDRNOTAVAIL WSAEADDRNOTAVAIL
+#undef EHOSTUNREACH
+#define EHOSTUNREACH WSAEHOSTUNREACH
+#undef ENOTCONN
+#define ENOTCONN WSAENOTCONN
 
 /*
  * Extended locale functions with gratuitous underscore prefixes.