Commit 79ff2e96 authored by Bruce Momjian's avatar Bruce Momjian

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
parent 6e8a1a67
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.73 2002/06/14 04:23:17 momjian Exp $ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.74 2002/06/15 20:01:31 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -351,6 +351,7 @@ pqPutInt(int value, size_t bytes, PGconn *conn) ...@@ -351,6 +351,7 @@ pqPutInt(int value, size_t bytes, PGconn *conn)
/* /*
* pqReadReady: is select() saying the file is ready to read? * pqReadReady: is select() saying the file is ready to read?
* JAB: -or- if SSL is enabled and used, is it buffering bytes?
* Returns -1 on failure, 0 if not ready, 1 if ready. * Returns -1 on failure, 0 if not ready, 1 if ready.
*/ */
int int
...@@ -362,6 +363,15 @@ pqReadReady(PGconn *conn) ...@@ -362,6 +363,15 @@ pqReadReady(PGconn *conn)
if (!conn || conn->sock < 0) if (!conn || conn->sock < 0)
return -1; return -1;
/* JAB: Check for SSL library buffering read bytes */
#ifdef USE_SSL
if (conn->ssl && SSL_pending(conn->ssl) > 0)
{
/* short-circuit the select */
return 1;
}
#endif
retry1: retry1:
FD_ZERO(&input_mask); FD_ZERO(&input_mask);
FD_SET(conn->sock, &input_mask); FD_SET(conn->sock, &input_mask);
...@@ -760,6 +770,9 @@ pqFlush(PGconn *conn) ...@@ -760,6 +770,9 @@ pqFlush(PGconn *conn)
/* /*
* pqWait: wait until we can read or write the connection socket * pqWait: wait until we can read or write the connection socket
* *
* JAB: If SSL enabled and used and forRead, buffered bytes short-circuit the
* call to select().
*
* We also stop waiting and return if the kernel flags an exception condition * We also stop waiting and return if the kernel flags an exception condition
* on the socket. The actual error condition will be detected and reported * on the socket. The actual error condition will be detected and reported
* when the caller tries to read or write the socket. * when the caller tries to read or write the socket.
...@@ -778,6 +791,15 @@ pqWait(int forRead, int forWrite, PGconn *conn) ...@@ -778,6 +791,15 @@ pqWait(int forRead, int forWrite, PGconn *conn)
return EOF; return EOF;
} }
/* JAB: Check for SSL library buffering read bytes */
#ifdef USE_SSL
if (forRead && conn->ssl && SSL_pending(conn->ssl) > 0)
{
/* short-circuit the select */
return 0;
}
#endif
if (forRead || forWrite) if (forRead || forWrite)
{ {
retry5: retry5:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment