Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fc0d3f1

Browse files
committed
pqWait() should check for exception status as well as read or write
ready. It appears that most (all?) Unixen will consider a socket to be read or write ready if it has an error condition, but of course Microsoft does things differently.
1 parent 8484f66 commit fc0d3f1

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/interfaces/libpq/fe-misc.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*
2626
*
2727
* IDENTIFICATION
28-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.47 2001/03/22 04:01:26 momjian Exp $
28+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.48 2001/03/31 23:13:30 tgl Exp $
2929
*
3030
*-------------------------------------------------------------------------
3131
*/
@@ -712,12 +712,17 @@ pqFlush(PGconn *conn)
712712

713713
/* --------------------------------------------------------------------- */
714714
/* pqWait: wait until we can read or write the connection socket
715+
*
716+
* We also stop waiting and return if the kernel flags an exception condition
717+
* on the socket. The actual error condition will be detected and reported
718+
* when the caller tries to read or write the socket.
715719
*/
716720
int
717721
pqWait(int forRead, int forWrite, PGconn *conn)
718722
{
719723
fd_set input_mask;
720724
fd_set output_mask;
725+
fd_set except_mask;
721726

722727
if (conn->sock < 0)
723728
{
@@ -731,17 +736,19 @@ pqWait(int forRead, int forWrite, PGconn *conn)
731736
retry:
732737
FD_ZERO(&input_mask);
733738
FD_ZERO(&output_mask);
739+
FD_ZERO(&except_mask);
734740
if (forRead)
735741
FD_SET(conn->sock, &input_mask);
736742
if (forWrite)
737743
FD_SET(conn->sock, &output_mask);
738-
if (select(conn->sock + 1, &input_mask, &output_mask, (fd_set *) NULL,
744+
FD_SET(conn->sock, &except_mask);
745+
if (select(conn->sock + 1, &input_mask, &output_mask, &except_mask,
739746
(struct timeval *) NULL) < 0)
740747
{
741748
if (errno == EINTR)
742749
goto retry;
743750
printfPQExpBuffer(&conn->errorMessage,
744-
"pqWait() -- select() failed: errno=%d\n%s\n",
751+
"pqWait() -- select() failed: errno=%d\n%s\n",
745752
errno, strerror(errno));
746753
return EOF;
747754
}

0 commit comments

Comments
 (0)