aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/libpq/fe-misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces/libpq/fe-misc.c')
-rw-r--r--src/interfaces/libpq/fe-misc.c50
1 files changed, 33 insertions, 17 deletions
diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c
index 64a05c8dbe5..a8af4d893ab 100644
--- a/src/interfaces/libpq/fe-misc.c
+++ b/src/interfaces/libpq/fe-misc.c
@@ -25,7 +25,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.71 2002/06/14 03:56:47 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.72 2002/06/14 04:09:37 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -55,13 +55,6 @@
#include "mb/pg_wchar.h"
#endif
-/* these functions are misnamed - they handle both SSL and non-SSL case */
-extern ssize_t read_SSL (PGconn *, void *ptr, size_t);
-extern ssize_t write_SSL (PGconn *, const void *ptr, size_t);
-
-#ifdef USE_SSL
-extern ssize_t close_SSL (PGconn *);
-#endif
#define DONOTICE(conn,message) \
((*(conn)->noticeHook) ((conn)->noticeArg, (message)))
@@ -484,8 +477,14 @@ pqReadData(PGconn *conn)
/* OK, try to read some data */
retry3:
- nread = read_SSL(conn, conn->inBuffer + conn->inEnd,
- conn->inBufSize - conn->inEnd);
+#ifdef USE_SSL
+ if (conn->ssl)
+ nread = SSL_read(conn->ssl, conn->inBuffer + conn->inEnd,
+ conn->inBufSize - conn->inEnd);
+ else
+#endif
+ nread = recv(conn->sock, conn->inBuffer + conn->inEnd,
+ conn->inBufSize - conn->inEnd, 0);
if (nread < 0)
{
if (SOCK_ERRNO == EINTR)
@@ -564,8 +563,14 @@ retry3:
* arrived.
*/
retry4:
- nread = read_SSL(conn, conn->inBuffer + conn->inEnd,
- conn->inBufSize - conn->inEnd);
+#ifdef USE_SSL
+ if (conn->ssl)
+ nread = SSL_read(conn->ssl, conn->inBuffer + conn->inEnd,
+ conn->inBufSize - conn->inEnd);
+ else
+#endif
+ nread = recv(conn->sock, conn->inBuffer + conn->inEnd,
+ conn->inBufSize - conn->inEnd, 0);
if (nread < 0)
{
if (SOCK_ERRNO == EINTR)
@@ -606,9 +611,6 @@ definitelyFailed:
"\tThis probably means the server terminated abnormally\n"
"\tbefore or while processing the request.\n"));
conn->status = CONNECTION_BAD; /* No more connection to backend */
-#ifdef USE_SSL
- close_SSL(conn);
-#endif
#ifdef WIN32
closesocket(conn->sock);
#else
@@ -648,9 +650,23 @@ pqSendSome(PGconn *conn)
/* while there's still data to send */
while (len > 0)
{
+ /* Prevent being SIGPIPEd if backend has closed the connection. */
+#ifndef WIN32
+ pqsigfunc oldsighandler = pqsignal(SIGPIPE, SIG_IGN);
+#endif
+
int sent;
- sent = write_SSL(conn, ptr, len);
+#ifdef USE_SSL
+ if (conn->ssl)
+ sent = SSL_write(conn->ssl, ptr, len);
+ else
+#endif
+ sent = send(conn->sock, ptr, len, 0);
+
+#ifndef WIN32
+ pqsignal(SIGPIPE, oldsighandler);
+#endif
if (sent < 0)
{
@@ -716,7 +732,7 @@ pqSendSome(PGconn *conn)
*/
#ifdef USE_SSL
/* can't do anything for our SSL users yet */
- if (PQgetssl(conn) == NULL)
+ if (conn->ssl == NULL)
{
#endif
if (pqIsnonblocking(conn))