mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
pgindent run for 8.3.
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/port/win32/socket.c,v 1.18 2007/06/04 13:39:28 mha Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/port/win32/socket.c,v 1.19 2007/11/15 21:14:37 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -103,14 +103,15 @@ pgwin32_poll_signals(void)
|
||||
}
|
||||
|
||||
static int
|
||||
isDataGram(SOCKET s) {
|
||||
int type;
|
||||
int typelen = sizeof(type);
|
||||
isDataGram(SOCKET s)
|
||||
{
|
||||
int type;
|
||||
int typelen = sizeof(type);
|
||||
|
||||
if ( getsockopt(s, SOL_SOCKET, SO_TYPE, (char*)&type, &typelen) )
|
||||
if (getsockopt(s, SOL_SOCKET, SO_TYPE, (char *) &type, &typelen))
|
||||
return 1;
|
||||
|
||||
return ( type == SOCK_DGRAM ) ? 1 : 0;
|
||||
return (type == SOCK_DGRAM) ? 1 : 0;
|
||||
}
|
||||
|
||||
int
|
||||
@ -118,7 +119,7 @@ pgwin32_waitforsinglesocket(SOCKET s, int what, int timeout)
|
||||
{
|
||||
static HANDLE waitevent = INVALID_HANDLE_VALUE;
|
||||
static SOCKET current_socket = -1;
|
||||
static int isUDP = 0;
|
||||
static int isUDP = 0;
|
||||
HANDLE events[2];
|
||||
int r;
|
||||
|
||||
@ -139,9 +140,9 @@ pgwin32_waitforsinglesocket(SOCKET s, int what, int timeout)
|
||||
* socket from a previous call
|
||||
*/
|
||||
|
||||
if (current_socket != s)
|
||||
if (current_socket != s)
|
||||
{
|
||||
if ( current_socket != -1 )
|
||||
if (current_socket != -1)
|
||||
WSAEventSelect(current_socket, waitevent, 0);
|
||||
isUDP = isDataGram(s);
|
||||
}
|
||||
@ -157,34 +158,32 @@ pgwin32_waitforsinglesocket(SOCKET s, int what, int timeout)
|
||||
events[0] = pgwin32_signal_event;
|
||||
events[1] = waitevent;
|
||||
|
||||
/*
|
||||
* Just a workaround of unknown locking problem with writing
|
||||
* in UDP socket under high load:
|
||||
* Client's pgsql backend sleeps infinitely in
|
||||
* WaitForMultipleObjectsEx, pgstat process sleeps in
|
||||
* pgwin32_select(). So, we will wait with small
|
||||
* timeout(0.1 sec) and if sockect is still blocked,
|
||||
* try WSASend (see comments in pgwin32_select) and wait again.
|
||||
/*
|
||||
* Just a workaround of unknown locking problem with writing in UDP socket
|
||||
* under high load: Client's pgsql backend sleeps infinitely in
|
||||
* WaitForMultipleObjectsEx, pgstat process sleeps in pgwin32_select().
|
||||
* So, we will wait with small timeout(0.1 sec) and if sockect is still
|
||||
* blocked, try WSASend (see comments in pgwin32_select) and wait again.
|
||||
*/
|
||||
if ((what & FD_WRITE) && isUDP)
|
||||
{
|
||||
for(;;)
|
||||
for (;;)
|
||||
{
|
||||
r = WaitForMultipleObjectsEx(2, events, FALSE, 100, TRUE);
|
||||
|
||||
if ( r == WAIT_TIMEOUT )
|
||||
if (r == WAIT_TIMEOUT)
|
||||
{
|
||||
char c;
|
||||
WSABUF buf;
|
||||
DWORD sent;
|
||||
char c;
|
||||
WSABUF buf;
|
||||
DWORD sent;
|
||||
|
||||
buf.buf = &c;
|
||||
buf.len = 0;
|
||||
|
||||
r = WSASend(s, &buf, 1, &sent, 0, NULL, NULL);
|
||||
if (r == 0) /* Completed - means things are fine! */
|
||||
if (r == 0) /* Completed - means things are fine! */
|
||||
return 1;
|
||||
else if ( WSAGetLastError() != WSAEWOULDBLOCK )
|
||||
else if (WSAGetLastError() != WSAEWOULDBLOCK)
|
||||
{
|
||||
TranslateSocketError();
|
||||
return 0;
|
||||
@ -291,7 +290,7 @@ pgwin32_recv(SOCKET s, char *buf, int len, int f)
|
||||
int r;
|
||||
DWORD b;
|
||||
DWORD flags = f;
|
||||
int n;
|
||||
int n;
|
||||
|
||||
if (pgwin32_poll_signals())
|
||||
return -1;
|
||||
@ -317,8 +316,8 @@ pgwin32_recv(SOCKET s, char *buf, int len, int f)
|
||||
{
|
||||
if (pgwin32_waitforsinglesocket(s, FD_READ | FD_CLOSE | FD_ACCEPT,
|
||||
INFINITE) == 0)
|
||||
return -1; /* errno already set */
|
||||
|
||||
return -1; /* errno already set */
|
||||
|
||||
r = WSARecv(s, &wbuf, 1, &b, &flags, NULL, NULL);
|
||||
if (r == SOCKET_ERROR)
|
||||
{
|
||||
@ -326,10 +325,11 @@ pgwin32_recv(SOCKET s, char *buf, int len, int f)
|
||||
{
|
||||
/*
|
||||
* There seem to be cases on win2k (at least) where WSARecv
|
||||
* can return WSAEWOULDBLOCK even when pgwin32_waitforsinglesocket
|
||||
* claims the socket is readable. In this case, just sleep for a
|
||||
* moment and try again. We try up to 5 times - if it fails more than
|
||||
* that it's not likely to ever come back.
|
||||
* can return WSAEWOULDBLOCK even when
|
||||
* pgwin32_waitforsinglesocket claims the socket is readable.
|
||||
* In this case, just sleep for a moment and try again. We try
|
||||
* up to 5 times - if it fails more than that it's not likely
|
||||
* to ever come back.
|
||||
*/
|
||||
pg_usleep(10000);
|
||||
continue;
|
||||
@ -340,7 +340,7 @@ pgwin32_recv(SOCKET s, char *buf, int len, int f)
|
||||
return b;
|
||||
}
|
||||
ereport(NOTICE,
|
||||
(errmsg_internal("Failed to read from ready socket (after retries)")));
|
||||
(errmsg_internal("Failed to read from ready socket (after retries)")));
|
||||
errno = EWOULDBLOCK;
|
||||
return -1;
|
||||
}
|
||||
@ -359,11 +359,11 @@ pgwin32_send(SOCKET s, char *buf, int len, int flags)
|
||||
wbuf.buf = buf;
|
||||
|
||||
/*
|
||||
* Readiness of socket to send data to UDP socket
|
||||
* may be not true: socket can become busy again! So loop
|
||||
* until send or error occurs.
|
||||
* Readiness of socket to send data to UDP socket may be not true: socket
|
||||
* can become busy again! So loop until send or error occurs.
|
||||
*/
|
||||
for(;;) {
|
||||
for (;;)
|
||||
{
|
||||
r = WSASend(s, &wbuf, 1, &b, flags, NULL, NULL);
|
||||
if (r != SOCKET_ERROR && b > 0)
|
||||
/* Write succeeded right away */
|
||||
|
Reference in New Issue
Block a user