Skip to content

Commit 79ff2e9

Browse files
committed
PATCH SSL_pending() checks in libpq/fe-misc.c:
I am no longer pursuing a total non-blocking implementation. I haven't found a good way to test it with the type of work that I do with PostgreSQL. I do use blocking SSL sockets with this mod and have had no problem whatsoever. The bug that I fixed in this patch is exceptionally hard to reproduce reliably. Jack Bates
1 parent 6e8a1a6 commit 79ff2e9

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/interfaces/libpq/fe-misc.c

Lines changed: 23 additions & 1 deletion
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.73 2002/06/14 04:23:17 momjian Exp $
28+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.74 2002/06/15 20:01:31 momjian Exp $
2929
*
3030
*-------------------------------------------------------------------------
3131
*/
@@ -351,6 +351,7 @@ pqPutInt(int value, size_t bytes, PGconn *conn)
351351

352352
/*
353353
* pqReadReady: is select() saying the file is ready to read?
354+
* JAB: -or- if SSL is enabled and used, is it buffering bytes?
354355
* Returns -1 on failure, 0 if not ready, 1 if ready.
355356
*/
356357
int
@@ -362,6 +363,15 @@ pqReadReady(PGconn *conn)
362363
if (!conn || conn->sock < 0)
363364
return -1;
364365

366+
/* JAB: Check for SSL library buffering read bytes */
367+
#ifdef USE_SSL
368+
if (conn->ssl && SSL_pending(conn->ssl) > 0)
369+
{
370+
/* short-circuit the select */
371+
return 1;
372+
}
373+
#endif
374+
365375
retry1:
366376
FD_ZERO(&input_mask);
367377
FD_SET(conn->sock, &input_mask);
@@ -760,6 +770,9 @@ pqFlush(PGconn *conn)
760770
/*
761771
* pqWait: wait until we can read or write the connection socket
762772
*
773+
* JAB: If SSL enabled and used and forRead, buffered bytes short-circuit the
774+
* call to select().
775+
*
763776
* We also stop waiting and return if the kernel flags an exception condition
764777
* on the socket. The actual error condition will be detected and reported
765778
* when the caller tries to read or write the socket.
@@ -778,6 +791,15 @@ pqWait(int forRead, int forWrite, PGconn *conn)
778791
return EOF;
779792
}
780793

794+
/* JAB: Check for SSL library buffering read bytes */
795+
#ifdef USE_SSL
796+
if (forRead && conn->ssl && SSL_pending(conn->ssl) > 0)
797+
{
798+
/* short-circuit the select */
799+
return 0;
800+
}
801+
#endif
802+
781803
if (forRead || forWrite)
782804
{
783805
retry5:

0 commit comments

Comments
 (0)