Commit 125ad539 authored by Tom Lane's avatar Tom Lane

Improve TranslateSocketError() to handle more Windows error codes.

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.
parent e5452815
...@@ -44,23 +44,38 @@ int pgwin32_noblock = 0; ...@@ -44,23 +44,38 @@ int pgwin32_noblock = 0;
/* /*
* Convert the last socket error code into errno * 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 static void
TranslateSocketError(void) TranslateSocketError(void)
{ {
switch (WSAGetLastError()) switch (WSAGetLastError())
{ {
case WSANOTINITIALISED:
case WSAENETDOWN:
case WSAEINPROGRESS:
case WSAEINVAL: case WSAEINVAL:
case WSAESOCKTNOSUPPORT: case WSANOTINITIALISED:
case WSAEFAULT:
case WSAEINVALIDPROVIDER: case WSAEINVALIDPROVIDER:
case WSAEINVALIDPROCTABLE: case WSAEINVALIDPROCTABLE:
case WSAEMSGSIZE: case WSAEDESTADDRREQ:
errno = EINVAL; errno = EINVAL;
break; break;
case WSAEINPROGRESS:
errno = EINPROGRESS;
break;
case WSAEFAULT:
errno = EFAULT;
break;
case WSAEISCONN:
errno = EISCONN;
break;
case WSAEMSGSIZE:
errno = EMSGSIZE;
break;
case WSAEAFNOSUPPORT: case WSAEAFNOSUPPORT:
errno = EAFNOSUPPORT; errno = EAFNOSUPPORT;
break; break;
...@@ -72,16 +87,23 @@ TranslateSocketError(void) ...@@ -72,16 +87,23 @@ TranslateSocketError(void)
break; break;
case WSAEPROTONOSUPPORT: case WSAEPROTONOSUPPORT:
case WSAEPROTOTYPE: case WSAEPROTOTYPE:
case WSAESOCKTNOSUPPORT:
errno = EPROTONOSUPPORT; errno = EPROTONOSUPPORT;
break; break;
case WSAECONNABORTED:
errno = ECONNABORTED;
break;
case WSAECONNREFUSED: case WSAECONNREFUSED:
errno = ECONNREFUSED; errno = ECONNREFUSED;
break; break;
case WSAECONNRESET:
errno = ECONNRESET;
break;
case WSAEINTR: case WSAEINTR:
errno = EINTR; errno = EINTR;
break; break;
case WSAENOTSOCK: case WSAENOTSOCK:
errno = EBADFD; errno = ENOTSOCK;
break; break;
case WSAEOPNOTSUPP: case WSAEOPNOTSUPP:
errno = EOPNOTSUPP; errno = EOPNOTSUPP;
...@@ -92,13 +114,24 @@ TranslateSocketError(void) ...@@ -92,13 +114,24 @@ TranslateSocketError(void)
case WSAEACCES: case WSAEACCES:
errno = EACCES; errno = EACCES;
break; 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 WSAENETRESET:
case WSAECONNRESET: errno = EHOSTUNREACH;
break;
case WSAENOTCONN:
case WSAESHUTDOWN: case WSAESHUTDOWN:
case WSAECONNABORTED:
case WSAEDISCON: case WSAEDISCON:
errno = ECONNREFUSED; /* ENOTCONN? */ errno = ENOTCONN;
break; break;
default: default:
ereport(NOTICE, ereport(NOTICE,
......
...@@ -285,20 +285,32 @@ typedef int pid_t; ...@@ -285,20 +285,32 @@ typedef int pid_t;
#define EAFNOSUPPORT WSAEAFNOSUPPORT #define EAFNOSUPPORT WSAEAFNOSUPPORT
#undef EWOULDBLOCK #undef EWOULDBLOCK
#define EWOULDBLOCK WSAEWOULDBLOCK #define EWOULDBLOCK WSAEWOULDBLOCK
#undef ECONNABORTED
#define ECONNABORTED WSAECONNABORTED
#undef ECONNRESET #undef ECONNRESET
#define ECONNRESET WSAECONNRESET #define ECONNRESET WSAECONNRESET
#undef EINPROGRESS #undef EINPROGRESS
#define EINPROGRESS WSAEINPROGRESS #define EINPROGRESS WSAEINPROGRESS
#undef EISCONN
#define EISCONN WSAEISCONN
#undef ENOBUFS #undef ENOBUFS
#define ENOBUFS WSAENOBUFS #define ENOBUFS WSAENOBUFS
#undef EPROTONOSUPPORT #undef EPROTONOSUPPORT
#define EPROTONOSUPPORT WSAEPROTONOSUPPORT #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
#undef ECONNREFUSED #undef ECONNREFUSED
#define ECONNREFUSED WSAECONNREFUSED #define ECONNREFUSED WSAECONNREFUSED
#undef EBADFD #undef ENOTSOCK
#define EBADFD WSAENOTSOCK #define ENOTSOCK WSAENOTSOCK
#undef EOPNOTSUPP #undef EOPNOTSUPP
#define EOPNOTSUPP WSAEOPNOTSUPP #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. * Extended locale functions with gratuitous underscore prefixes.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment