PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
socket.c File Reference
#include "postgres.h"
Include dependency graph for socket.c:

Go to the source code of this file.

Functions

static void TranslateSocketError (void)
 
static int pgwin32_poll_signals (void)
 
static int isDataGram (SOCKET s)
 
int pgwin32_waitforsinglesocket (SOCKET s, int what, int timeout)
 
SOCKET pgwin32_socket (int af, int type, int protocol)
 
int pgwin32_bind (SOCKET s, struct sockaddr *addr, int addrlen)
 
int pgwin32_listen (SOCKET s, int backlog)
 
SOCKET pgwin32_accept (SOCKET s, struct sockaddr *addr, int *addrlen)
 
int pgwin32_connect (SOCKET s, const struct sockaddr *addr, int addrlen)
 
int pgwin32_recv (SOCKET s, char *buf, int len, int f)
 
int pgwin32_send (SOCKET s, const void *buf, int len, int flags)
 
int pgwin32_select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timeval *timeout)
 
const char * pgwin32_socket_strerror (int err)
 

Variables

int pgwin32_noblock = 0
 
static char wserrbuf [256]
 

Function Documentation

static int isDataGram ( SOCKET  s)
static

Definition at line 156 of file socket.c.

Referenced by pgwin32_waitforsinglesocket().

157 {
158  int type;
159  int typelen = sizeof(type);
160 
161  if (getsockopt(s, SOL_SOCKET, SO_TYPE, (char *) &type, &typelen))
162  return 1;
163 
164  return (type == SOCK_DGRAM) ? 1 : 0;
165 }
SOCKET pgwin32_accept ( SOCKET  s,
struct sockaddr *  addr,
int *  addrlen 
)

Definition at line 323 of file socket.c.

References NULL, pgwin32_poll_signals(), and TranslateSocketError().

324 {
325  SOCKET rs;
326 
327  /*
328  * Poll for signals, but don't return with EINTR, since we don't handle
329  * that in pqcomm.c
330  */
332 
333  rs = WSAAccept(s, addr, addrlen, NULL, 0);
334  if (rs == INVALID_SOCKET)
335  {
337  return INVALID_SOCKET;
338  }
339  return rs;
340 }
static int pgwin32_poll_signals(void)
Definition: socket.c:144
static void TranslateSocketError(void)
Definition: socket.c:56
#define NULL
Definition: c.h:229
int pgwin32_bind ( SOCKET  s,
struct sockaddr *  addr,
int  addrlen 
)

Definition at line 301 of file socket.c.

References bind, and TranslateSocketError().

302 {
303  int res;
304 
305  res = bind(s, addr, addrlen);
306  if (res < 0)
308  return res;
309 }
#define bind(s, addr, addrlen)
Definition: win32.h:370
static void TranslateSocketError(void)
Definition: socket.c:56
int pgwin32_connect ( SOCKET  s,
const struct sockaddr *  addr,
int  addrlen 
)

Definition at line 345 of file socket.c.

References NULL, pgwin32_waitforsinglesocket(), and TranslateSocketError().

346 {
347  int r;
348 
349  r = WSAConnect(s, addr, addrlen, NULL, NULL, NULL, NULL);
350  if (r == 0)
351  return 0;
352 
353  if (WSAGetLastError() != WSAEWOULDBLOCK)
354  {
356  return -1;
357  }
358 
359  while (pgwin32_waitforsinglesocket(s, FD_CONNECT, INFINITE) == 0)
360  {
361  /* Loop endlessly as long as we are just delivering signals */
362  }
363 
364  return 0;
365 }
int pgwin32_waitforsinglesocket(SOCKET s, int what, int timeout)
Definition: socket.c:168
static void TranslateSocketError(void)
Definition: socket.c:56
#define NULL
Definition: c.h:229
int pgwin32_listen ( SOCKET  s,
int  backlog 
)

Definition at line 312 of file socket.c.

References listen, and TranslateSocketError().

313 {
314  int res;
315 
316  res = listen(s, backlog);
317  if (res < 0)
319  return res;
320 }
static void TranslateSocketError(void)
Definition: socket.c:56
#define listen(s, backlog)
Definition: win32.h:371
static int pgwin32_poll_signals ( void  )
static

Definition at line 144 of file socket.c.

References EINTR, pgwin32_dispatch_queued_signals(), and UNBLOCKED_SIGNAL_QUEUE.

Referenced by pgwin32_accept(), pgwin32_recv(), pgwin32_select(), and pgwin32_send().

145 {
147  {
149  errno = EINTR;
150  return 1;
151  }
152  return 0;
153 }
void pgwin32_dispatch_queued_signals(void)
Definition: signal.c:107
#define UNBLOCKED_SIGNAL_QUEUE()
Definition: win32.h:359
#define EINTR
Definition: win32.h:285
int pgwin32_recv ( SOCKET  s,
char *  buf,
int  len,
int  f 
)

Definition at line 368 of file socket.c.

References buf, ereport, errmsg_internal(), EWOULDBLOCK, NOTICE, NULL, pg_usleep(), pgwin32_noblock, pgwin32_poll_signals(), pgwin32_waitforsinglesocket(), and TranslateSocketError().

369 {
370  WSABUF wbuf;
371  int r;
372  DWORD b;
373  DWORD flags = f;
374  int n;
375 
376  if (pgwin32_poll_signals())
377  return -1;
378 
379  wbuf.len = len;
380  wbuf.buf = buf;
381 
382  r = WSARecv(s, &wbuf, 1, &b, &flags, NULL, NULL);
383  if (r != SOCKET_ERROR)
384  return b; /* success */
385 
386  if (WSAGetLastError() != WSAEWOULDBLOCK)
387  {
389  return -1;
390  }
391 
392  if (pgwin32_noblock)
393  {
394  /*
395  * No data received, and we are in "emulated non-blocking mode", so
396  * return indicating that we'd block if we were to continue.
397  */
398  errno = EWOULDBLOCK;
399  return -1;
400  }
401 
402  /* We're in blocking mode, so wait for data */
403 
404  for (n = 0; n < 5; n++)
405  {
406  if (pgwin32_waitforsinglesocket(s, FD_READ | FD_CLOSE | FD_ACCEPT,
407  INFINITE) == 0)
408  return -1; /* errno already set */
409 
410  r = WSARecv(s, &wbuf, 1, &b, &flags, NULL, NULL);
411  if (r != SOCKET_ERROR)
412  return b; /* success */
413  if (WSAGetLastError() != WSAEWOULDBLOCK)
414  {
416  return -1;
417  }
418 
419  /*
420  * There seem to be cases on win2k (at least) where WSARecv can return
421  * WSAEWOULDBLOCK even when pgwin32_waitforsinglesocket claims the
422  * socket is readable. In this case, just sleep for a moment and try
423  * again. We try up to 5 times - if it fails more than that it's not
424  * likely to ever come back.
425  */
426  pg_usleep(10000);
427  }
428  ereport(NOTICE,
429  (errmsg_internal("could not read from ready socket (after retries)")));
430  errno = EWOULDBLOCK;
431  return -1;
432 }
#define EWOULDBLOCK
Definition: win32.h:291
int pgwin32_noblock
Definition: socket.c:28
void pg_usleep(long microsec)
Definition: signal.c:53
static int pgwin32_poll_signals(void)
Definition: socket.c:144
static char * buf
Definition: pg_test_fsync.c:66
int pgwin32_waitforsinglesocket(SOCKET s, int what, int timeout)
Definition: socket.c:168
#define ereport(elevel, rest)
Definition: elog.h:122
static void TranslateSocketError(void)
Definition: socket.c:56
#define NOTICE
Definition: elog.h:37
int errmsg_internal(const char *fmt,...)
Definition: elog.c:827
#define NULL
Definition: c.h:229
int pgwin32_select ( int  nfds,
fd_set *  readfds,
fd_set *  writefds,
fd_set *  exceptfds,
const struct timeval *  timeout 
)

Definition at line 503 of file socket.c.

References Assert, buf, EINTR, elog, ERROR, FALSE, i, NULL, pgwin32_dispatch_queued_signals(), pgwin32_poll_signals(), pgwin32_signal_event, TranslateSocketError(), and TRUE.

504 {
505  WSAEVENT events[FD_SETSIZE * 2]; /* worst case is readfds totally
506  * different from writefds, so
507  * 2*FD_SETSIZE sockets */
508  SOCKET sockets[FD_SETSIZE * 2];
509  int numevents = 0;
510  int i;
511  int r;
512  DWORD timeoutval = WSA_INFINITE;
513  FD_SET outreadfds;
514  FD_SET outwritefds;
515  int nummatches = 0;
516 
517  Assert(exceptfds == NULL);
518 
519  if (pgwin32_poll_signals())
520  return -1;
521 
522  FD_ZERO(&outreadfds);
523  FD_ZERO(&outwritefds);
524 
525  /*
526  * Windows does not guarantee to log an FD_WRITE network event indicating
527  * that more data can be sent unless the previous send() failed with
528  * WSAEWOULDBLOCK. While our caller might well have made such a call, we
529  * cannot assume that here. Therefore, if waiting for write-ready, force
530  * the issue by doing a dummy send(). If the dummy send() succeeds,
531  * assume that the socket is in fact write-ready, and return immediately.
532  * Also, if it fails with something other than WSAEWOULDBLOCK, return a
533  * write-ready indication to let our caller deal with the error condition.
534  */
535  if (writefds != NULL)
536  {
537  for (i = 0; i < writefds->fd_count; i++)
538  {
539  char c;
540  WSABUF buf;
541  DWORD sent;
542 
543  buf.buf = &c;
544  buf.len = 0;
545 
546  r = WSASend(writefds->fd_array[i], &buf, 1, &sent, 0, NULL, NULL);
547  if (r == 0 || WSAGetLastError() != WSAEWOULDBLOCK)
548  FD_SET(writefds->fd_array[i], &outwritefds);
549  }
550 
551  /* If we found any write-ready sockets, just return them immediately */
552  if (outwritefds.fd_count > 0)
553  {
554  memcpy(writefds, &outwritefds, sizeof(fd_set));
555  if (readfds)
556  FD_ZERO(readfds);
557  return outwritefds.fd_count;
558  }
559  }
560 
561 
562  /* Now set up for an actual select */
563 
564  if (timeout != NULL)
565  {
566  /* timeoutval is in milliseconds */
567  timeoutval = timeout->tv_sec * 1000 + timeout->tv_usec / 1000;
568  }
569 
570  if (readfds != NULL)
571  {
572  for (i = 0; i < readfds->fd_count; i++)
573  {
574  events[numevents] = WSACreateEvent();
575  sockets[numevents] = readfds->fd_array[i];
576  numevents++;
577  }
578  }
579  if (writefds != NULL)
580  {
581  for (i = 0; i < writefds->fd_count; i++)
582  {
583  if (!readfds ||
584  !FD_ISSET(writefds->fd_array[i], readfds))
585  {
586  /* If the socket is not in the read list */
587  events[numevents] = WSACreateEvent();
588  sockets[numevents] = writefds->fd_array[i];
589  numevents++;
590  }
591  }
592  }
593 
594  for (i = 0; i < numevents; i++)
595  {
596  int flags = 0;
597 
598  if (readfds && FD_ISSET(sockets[i], readfds))
599  flags |= FD_READ | FD_ACCEPT | FD_CLOSE;
600 
601  if (writefds && FD_ISSET(sockets[i], writefds))
602  flags |= FD_WRITE | FD_CLOSE;
603 
604  if (WSAEventSelect(sockets[i], events[i], flags) != 0)
605  {
607  /* release already-assigned event objects */
608  while (--i >= 0)
609  WSAEventSelect(sockets[i], NULL, 0);
610  for (i = 0; i < numevents; i++)
611  WSACloseEvent(events[i]);
612  return -1;
613  }
614  }
615 
616  events[numevents] = pgwin32_signal_event;
617  r = WaitForMultipleObjectsEx(numevents + 1, events, FALSE, timeoutval, TRUE);
618  if (r != WAIT_TIMEOUT && r != WAIT_IO_COMPLETION && r != (WAIT_OBJECT_0 + numevents))
619  {
620  /*
621  * We scan all events, even those not signalled, in case more than one
622  * event has been tagged but Wait.. can only return one.
623  */
624  WSANETWORKEVENTS resEvents;
625 
626  for (i = 0; i < numevents; i++)
627  {
628  ZeroMemory(&resEvents, sizeof(resEvents));
629  if (WSAEnumNetworkEvents(sockets[i], events[i], &resEvents) != 0)
630  elog(ERROR, "failed to enumerate network events: error code %u",
631  WSAGetLastError());
632  /* Read activity? */
633  if (readfds && FD_ISSET(sockets[i], readfds))
634  {
635  if ((resEvents.lNetworkEvents & FD_READ) ||
636  (resEvents.lNetworkEvents & FD_ACCEPT) ||
637  (resEvents.lNetworkEvents & FD_CLOSE))
638  {
639  FD_SET(sockets[i], &outreadfds);
640 
641  nummatches++;
642  }
643  }
644  /* Write activity? */
645  if (writefds && FD_ISSET(sockets[i], writefds))
646  {
647  if ((resEvents.lNetworkEvents & FD_WRITE) ||
648  (resEvents.lNetworkEvents & FD_CLOSE))
649  {
650  FD_SET(sockets[i], &outwritefds);
651 
652  nummatches++;
653  }
654  }
655  }
656  }
657 
658  /* Clean up all the event objects */
659  for (i = 0; i < numevents; i++)
660  {
661  WSAEventSelect(sockets[i], NULL, 0);
662  WSACloseEvent(events[i]);
663  }
664 
665  if (r == WSA_WAIT_TIMEOUT)
666  {
667  if (readfds)
668  FD_ZERO(readfds);
669  if (writefds)
670  FD_ZERO(writefds);
671  return 0;
672  }
673 
674  /* Signal-like events. */
675  if (r == WAIT_OBJECT_0 + numevents || r == WAIT_IO_COMPLETION)
676  {
678  errno = EINTR;
679  if (readfds)
680  FD_ZERO(readfds);
681  if (writefds)
682  FD_ZERO(writefds);
683  return -1;
684  }
685 
686  /* Overwrite socket sets with our resulting values */
687  if (readfds)
688  memcpy(readfds, &outreadfds, sizeof(fd_set));
689  if (writefds)
690  memcpy(writefds, &outwritefds, sizeof(fd_set));
691  return nummatches;
692 }
HANDLE pgwin32_signal_event
Definition: signal.c:27
void pgwin32_dispatch_queued_signals(void)
Definition: signal.c:107
#define ERROR
Definition: elog.h:43
#define FALSE
Definition: c.h:221
static int pgwin32_poll_signals(void)
Definition: socket.c:144
char * c
static char * buf
Definition: pg_test_fsync.c:66
static void TranslateSocketError(void)
Definition: socket.c:56
#define EINTR
Definition: win32.h:285
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
int i
#define TRUE
Definition: c.h:217
#define elog
Definition: elog.h:219
int pgwin32_send ( SOCKET  s,
const void *  buf,
int  len,
int  flags 
)

Definition at line 445 of file socket.c.

References EWOULDBLOCK, NULL, pgwin32_noblock, pgwin32_poll_signals(), pgwin32_waitforsinglesocket(), and TranslateSocketError().

446 {
447  WSABUF wbuf;
448  int r;
449  DWORD b;
450 
451  if (pgwin32_poll_signals())
452  return -1;
453 
454  wbuf.len = len;
455  wbuf.buf = (char *) buf;
456 
457  /*
458  * Readiness of socket to send data to UDP socket may be not true: socket
459  * can become busy again! So loop until send or error occurs.
460  */
461  for (;;)
462  {
463  r = WSASend(s, &wbuf, 1, &b, flags, NULL, NULL);
464  if (r != SOCKET_ERROR && b > 0)
465  /* Write succeeded right away */
466  return b;
467 
468  if (r == SOCKET_ERROR &&
469  WSAGetLastError() != WSAEWOULDBLOCK)
470  {
472  return -1;
473  }
474 
475  if (pgwin32_noblock)
476  {
477  /*
478  * No data sent, and we are in "emulated non-blocking mode", so
479  * return indicating that we'd block if we were to continue.
480  */
481  errno = EWOULDBLOCK;
482  return -1;
483  }
484 
485  /* No error, zero bytes (win2000+) or error+WSAEWOULDBLOCK (<=nt4) */
486 
487  if (pgwin32_waitforsinglesocket(s, FD_WRITE | FD_CLOSE, INFINITE) == 0)
488  return -1;
489  }
490 
491  return -1;
492 }
#define EWOULDBLOCK
Definition: win32.h:291
int pgwin32_noblock
Definition: socket.c:28
static int pgwin32_poll_signals(void)
Definition: socket.c:144
static char * buf
Definition: pg_test_fsync.c:66
int pgwin32_waitforsinglesocket(SOCKET s, int what, int timeout)
Definition: socket.c:168
static void TranslateSocketError(void)
Definition: socket.c:56
#define NULL
Definition: c.h:229
SOCKET pgwin32_socket ( int  af,
int  type,
int  protocol 
)

Definition at line 278 of file socket.c.

References NULL, and TranslateSocketError().

279 {
280  SOCKET s;
281  unsigned long on = 1;
282 
283  s = WSASocket(af, type, protocol, NULL, 0, WSA_FLAG_OVERLAPPED);
284  if (s == INVALID_SOCKET)
285  {
287  return INVALID_SOCKET;
288  }
289 
290  if (ioctlsocket(s, FIONBIO, &on))
291  {
293  return INVALID_SOCKET;
294  }
295  errno = 0;
296 
297  return s;
298 }
static void TranslateSocketError(void)
Definition: socket.c:56
#define NULL
Definition: c.h:229
const char* pgwin32_socket_strerror ( int  err)

Definition at line 701 of file socket.c.

References ereport, errmsg_internal(), FATAL, NULL, and wserrbuf.

Referenced by useful_strerror().

702 {
703  static HANDLE handleDLL = INVALID_HANDLE_VALUE;
704 
705  if (handleDLL == INVALID_HANDLE_VALUE)
706  {
707  handleDLL = LoadLibraryEx("netmsg.dll", NULL, DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE);
708  if (handleDLL == NULL)
709  ereport(FATAL,
710  (errmsg_internal("could not load netmsg.dll: error code %lu", GetLastError())));
711  }
712 
713  ZeroMemory(&wserrbuf, sizeof(wserrbuf));
714  if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS |
715  FORMAT_MESSAGE_FROM_SYSTEM |
716  FORMAT_MESSAGE_FROM_HMODULE,
717  handleDLL,
718  err,
719  MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT),
720  wserrbuf,
721  sizeof(wserrbuf) - 1,
722  NULL) == 0)
723  {
724  /* Failed to get id */
725  sprintf(wserrbuf, "unrecognized winsock error %d", err);
726  }
727  return wserrbuf;
728 }
#define FATAL
Definition: elog.h:52
static char wserrbuf[256]
Definition: socket.c:699
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg_internal(const char *fmt,...)
Definition: elog.c:827
#define NULL
Definition: c.h:229
int pgwin32_waitforsinglesocket ( SOCKET  s,
int  what,
int  timeout 
)

Definition at line 168 of file socket.c.

References buf, EINTR, ereport, errmsg_internal(), ERROR, EWOULDBLOCK, FALSE, isDataGram(), NULL, pgwin32_dispatch_queued_signals(), pgwin32_signal_event, TranslateSocketError(), and TRUE.

Referenced by pgwin32_connect(), pgwin32_recv(), and pgwin32_send().

169 {
170  static HANDLE waitevent = INVALID_HANDLE_VALUE;
171  static SOCKET current_socket = INVALID_SOCKET;
172  static int isUDP = 0;
173  HANDLE events[2];
174  int r;
175 
176  /* Create an event object just once and use it on all future calls */
177  if (waitevent == INVALID_HANDLE_VALUE)
178  {
179  waitevent = CreateEvent(NULL, TRUE, FALSE, NULL);
180 
181  if (waitevent == INVALID_HANDLE_VALUE)
182  ereport(ERROR,
183  (errmsg_internal("could not create socket waiting event: error code %lu", GetLastError())));
184  }
185  else if (!ResetEvent(waitevent))
186  ereport(ERROR,
187  (errmsg_internal("could not reset socket waiting event: error code %lu", GetLastError())));
188 
189  /*
190  * Track whether socket is UDP or not. (NB: most likely, this is both
191  * useless and wrong; there is no reason to think that the behavior of
192  * WSAEventSelect is different for TCP and UDP.)
193  */
194  if (current_socket != s)
195  isUDP = isDataGram(s);
196  current_socket = s;
197 
198  /*
199  * Attach event to socket. NOTE: we must detach it again before
200  * returning, since other bits of code may try to attach other events to
201  * the socket.
202  */
203  if (WSAEventSelect(s, waitevent, what) != 0)
204  {
206  return 0;
207  }
208 
209  events[0] = pgwin32_signal_event;
210  events[1] = waitevent;
211 
212  /*
213  * Just a workaround of unknown locking problem with writing in UDP socket
214  * under high load: Client's pgsql backend sleeps infinitely in
215  * WaitForMultipleObjectsEx, pgstat process sleeps in pgwin32_select().
216  * So, we will wait with small timeout(0.1 sec) and if socket is still
217  * blocked, try WSASend (see comments in pgwin32_select) and wait again.
218  */
219  if ((what & FD_WRITE) && isUDP)
220  {
221  for (;;)
222  {
223  r = WaitForMultipleObjectsEx(2, events, FALSE, 100, TRUE);
224 
225  if (r == WAIT_TIMEOUT)
226  {
227  char c;
228  WSABUF buf;
229  DWORD sent;
230 
231  buf.buf = &c;
232  buf.len = 0;
233 
234  r = WSASend(s, &buf, 1, &sent, 0, NULL, NULL);
235  if (r == 0) /* Completed - means things are fine! */
236  {
237  WSAEventSelect(s, NULL, 0);
238  return 1;
239  }
240  else if (WSAGetLastError() != WSAEWOULDBLOCK)
241  {
243  WSAEventSelect(s, NULL, 0);
244  return 0;
245  }
246  }
247  else
248  break;
249  }
250  }
251  else
252  r = WaitForMultipleObjectsEx(2, events, FALSE, timeout, TRUE);
253 
254  WSAEventSelect(s, NULL, 0);
255 
256  if (r == WAIT_OBJECT_0 || r == WAIT_IO_COMPLETION)
257  {
259  errno = EINTR;
260  return 0;
261  }
262  if (r == WAIT_OBJECT_0 + 1)
263  return 1;
264  if (r == WAIT_TIMEOUT)
265  {
266  errno = EWOULDBLOCK;
267  return 0;
268  }
269  ereport(ERROR,
270  (errmsg_internal("unrecognized return value from WaitForMultipleObjects: %d (error code %lu)", r, GetLastError())));
271  return 0;
272 }
#define EWOULDBLOCK
Definition: win32.h:291
HANDLE pgwin32_signal_event
Definition: signal.c:27
void pgwin32_dispatch_queued_signals(void)
Definition: signal.c:107
#define ERROR
Definition: elog.h:43
#define FALSE
Definition: c.h:221
char * c
static char * buf
Definition: pg_test_fsync.c:66
#define ereport(elevel, rest)
Definition: elog.h:122
static void TranslateSocketError(void)
Definition: socket.c:56
static int isDataGram(SOCKET s)
Definition: socket.c:156
#define EINTR
Definition: win32.h:285
int errmsg_internal(const char *fmt,...)
Definition: elog.c:827
#define NULL
Definition: c.h:229
#define TRUE
Definition: c.h:217
static void TranslateSocketError ( void  )
static

Definition at line 56 of file socket.c.

References EADDRINUSE, EADDRNOTAVAIL, EAFNOSUPPORT, ECONNABORTED, ECONNREFUSED, ECONNRESET, EHOSTUNREACH, EINPROGRESS, EINTR, EISCONN, EMSGSIZE, ENOBUFS, ENOTCONN, ENOTSOCK, EOPNOTSUPP, EPROTONOSUPPORT, ereport, errmsg_internal(), EWOULDBLOCK, and NOTICE.

Referenced by pgwin32_accept(), pgwin32_bind(), pgwin32_connect(), pgwin32_listen(), pgwin32_recv(), pgwin32_select(), pgwin32_send(), pgwin32_socket(), and pgwin32_waitforsinglesocket().

57 {
58  switch (WSAGetLastError())
59  {
60  case WSAEINVAL:
61  case WSANOTINITIALISED:
62  case WSAEINVALIDPROVIDER:
63  case WSAEINVALIDPROCTABLE:
64  case WSAEDESTADDRREQ:
65  errno = EINVAL;
66  break;
67  case WSAEINPROGRESS:
68  errno = EINPROGRESS;
69  break;
70  case WSAEFAULT:
71  errno = EFAULT;
72  break;
73  case WSAEISCONN:
74  errno = EISCONN;
75  break;
76  case WSAEMSGSIZE:
77  errno = EMSGSIZE;
78  break;
79  case WSAEAFNOSUPPORT:
80  errno = EAFNOSUPPORT;
81  break;
82  case WSAEMFILE:
83  errno = EMFILE;
84  break;
85  case WSAENOBUFS:
86  errno = ENOBUFS;
87  break;
88  case WSAEPROTONOSUPPORT:
89  case WSAEPROTOTYPE:
90  case WSAESOCKTNOSUPPORT:
91  errno = EPROTONOSUPPORT;
92  break;
93  case WSAECONNABORTED:
94  errno = ECONNABORTED;
95  break;
96  case WSAECONNREFUSED:
97  errno = ECONNREFUSED;
98  break;
99  case WSAECONNRESET:
100  errno = ECONNRESET;
101  break;
102  case WSAEINTR:
103  errno = EINTR;
104  break;
105  case WSAENOTSOCK:
106  errno = ENOTSOCK;
107  break;
108  case WSAEOPNOTSUPP:
109  errno = EOPNOTSUPP;
110  break;
111  case WSAEWOULDBLOCK:
112  errno = EWOULDBLOCK;
113  break;
114  case WSAEACCES:
115  errno = EACCES;
116  break;
117  case WSAEADDRINUSE:
118  errno = EADDRINUSE;
119  break;
120  case WSAEADDRNOTAVAIL:
121  errno = EADDRNOTAVAIL;
122  break;
123  case WSAEHOSTUNREACH:
124  case WSAEHOSTDOWN:
125  case WSAHOST_NOT_FOUND:
126  case WSAENETDOWN:
127  case WSAENETUNREACH:
128  case WSAENETRESET:
129  errno = EHOSTUNREACH;
130  break;
131  case WSAENOTCONN:
132  case WSAESHUTDOWN:
133  case WSAEDISCON:
134  errno = ENOTCONN;
135  break;
136  default:
137  ereport(NOTICE,
138  (errmsg_internal("unrecognized win32 socket error code: %d", WSAGetLastError())));
139  errno = EINVAL;
140  }
141 }
#define EWOULDBLOCK
Definition: win32.h:291
#define ENOTCONN
Definition: win32.h:317
#define EADDRINUSE
Definition: win32.h:311
#define EADDRNOTAVAIL
Definition: win32.h:313
#define ECONNREFUSED
Definition: win32.h:305
#define EINPROGRESS
Definition: win32.h:297
#define EOPNOTSUPP
Definition: win32.h:309
#define ECONNRESET
Definition: win32.h:295
#define EMSGSIZE
Definition: win32.h:287
#define EPROTONOSUPPORT
Definition: win32.h:303
#define EHOSTUNREACH
Definition: win32.h:315
#define ereport(elevel, rest)
Definition: elog.h:122
#define ENOTSOCK
Definition: win32.h:307
#define EAFNOSUPPORT
Definition: win32.h:289
#define EISCONN
Definition: win32.h:299
#define EINTR
Definition: win32.h:285
#define NOTICE
Definition: elog.h:37
int errmsg_internal(const char *fmt,...)
Definition: elog.c:827
#define ECONNABORTED
Definition: win32.h:293
#define ENOBUFS
Definition: win32.h:301

Variable Documentation

int pgwin32_noblock = 0
char wserrbuf[256]
static

Definition at line 699 of file socket.c.

Referenced by pgwin32_socket_strerror().