Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit215cbc9

Browse files
committed
Add emulation of non-blocking sockets to the win32 socket/signal layer,
and use this in pq_getbyte_if_available.It's only a limited implementation which swithes the whole emulation layerno non-blocking mode, but that's enough as long as non-blocking is onlyused during a short period of time, and only one socket is accessed duringthis time.
1 parent492eaef commit215cbc9

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

‎src/backend/libpq/pqcomm.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
3131
* Portions Copyright (c) 1994, Regents of the University of California
3232
*
33-
*$PostgreSQL: pgsql/src/backend/libpq/pqcomm.c,v 1.202 2010/01/15 09:19:02heikki Exp $
33+
*$PostgreSQL: pgsql/src/backend/libpq/pqcomm.c,v 1.203 2010/02/1619:26:02mha Exp $
3434
*
3535
*-------------------------------------------------------------------------
3636
*/
@@ -837,9 +837,13 @@ pq_getbyte_if_available(unsigned char *c)
837837
}
838838

839839
/* Temporarily put the socket into non-blocking mode */
840+
#ifdefWIN32
841+
pgwin32_noblock=1;
842+
#else
840843
if (!pg_set_noblock(MyProcPort->sock))
841844
ereport(ERROR,
842845
(errmsg("couldn't put socket to non-blocking mode: %m")));
846+
#endif
843847
MyProcPort->noblock= true;
844848
PG_TRY();
845849
{
@@ -851,16 +855,24 @@ pq_getbyte_if_available(unsigned char *c)
851855
* The rest of the backend code assumes the socket is in blocking
852856
* mode, so treat failure as FATAL.
853857
*/
858+
#ifdefWIN32
859+
pgwin32_noblock=0;
860+
#else
854861
if (!pg_set_block(MyProcPort->sock))
855862
ereport(FATAL,
856863
(errmsg("couldn't put socket to blocking mode: %m")));
864+
#endif
857865
MyProcPort->noblock= false;
858866
PG_RE_THROW();
859867
}
860868
PG_END_TRY();
869+
#ifdefWIN32
870+
pgwin32_noblock=0;
871+
#else
861872
if (!pg_set_block(MyProcPort->sock))
862873
ereport(FATAL,
863874
(errmsg("couldn't put socket to blocking mode: %m")));
875+
#endif
864876
MyProcPort->noblock= false;
865877

866878
returnr;

‎src/backend/port/win32/socket.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,26 @@
66
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
77
*
88
* IDENTIFICATION
9-
* $PostgreSQL: pgsql/src/backend/port/win32/socket.c,v 1.23 2010/01/02 16:57:50 momjian Exp $
9+
* $PostgreSQL: pgsql/src/backend/port/win32/socket.c,v 1.24 2010/02/16 19:26:02 mha Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
1313

1414
#include"postgres.h"
1515

16+
/*
17+
* Indicate if pgwin32_recv() should operate in non-blocking mode.
18+
*
19+
* Since the socket emulation layer always sets the actual socket to
20+
* non-blocking mode in order to be able to deliver signals, we must
21+
* specify this in a separate flag if we actually need non-blocking
22+
* operation.
23+
*
24+
* This flag changes the behaviour *globally* for all socket operations,
25+
* so it should only be set for very short periods of time.
26+
*/
27+
intpgwin32_noblock=0;
28+
1629
#undef socket
1730
#undef accept
1831
#undef connect
@@ -310,6 +323,16 @@ pgwin32_recv(SOCKET s, char *buf, int len, int f)
310323
return-1;
311324
}
312325

326+
if (pgwin32_noblock)
327+
{
328+
/*
329+
* No data received, and we are in "emulated non-blocking mode", so return
330+
* indicating thta we'd block if we were to continue.
331+
*/
332+
errno=EWOULDBLOCK;
333+
return-1;
334+
}
335+
313336
/* No error, zero bytes (win2000+) or error+WSAEWOULDBLOCK (<=nt4) */
314337

315338
for (n=0;n<5;n++)

‎src/include/port/win32.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.92 2010/02/13 02:34:14 tgl Exp $ */
1+
/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.93 2010/02/16 19:26:02 mha Exp $ */
22

33
#if defined(_MSC_VER)|| defined(__BORLANDC__)
44
#defineWIN32_ONLY_COMPILER
@@ -283,6 +283,8 @@ intpgwin32_send(SOCKET s, char *buf, int len, int flags);
283283
constchar*pgwin32_socket_strerror(interr);
284284
intpgwin32_waitforsinglesocket(SOCKETs,intwhat,inttimeout);
285285

286+
externintpgwin32_noblock;
287+
286288
/* in backend/port/win32/security.c */
287289
externintpgwin32_is_admin(void);
288290
externintpgwin32_is_service(void);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp