Commit bcf23ba4 authored by Tom Lane's avatar Tom Lane

Fix previous patch so it also works if not USE_SSL (mea culpa).

On balance, the need to cover this case changes my mind in favor of pushing
all error-message generation duties into the two fe-secure.c routines.
So do it that way.
parent fee476da
...@@ -578,7 +578,6 @@ pqReadData(PGconn *conn) ...@@ -578,7 +578,6 @@ pqReadData(PGconn *conn)
{ {
int someread = 0; int someread = 0;
int nread; int nread;
char sebuf[256];
if (conn->sock < 0) if (conn->sock < 0)
{ {
...@@ -647,11 +646,7 @@ retry3: ...@@ -647,11 +646,7 @@ retry3:
if (SOCK_ERRNO == ECONNRESET) if (SOCK_ERRNO == ECONNRESET)
goto definitelyFailed; goto definitelyFailed;
#endif #endif
/* in SSL mode, pqsecure_read set the error message */ /* pqsecure_read set the error message for us */
if (conn->ssl == NULL)
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not receive data from server: %s\n"),
SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
return -1; return -1;
} }
if (nread > 0) if (nread > 0)
...@@ -711,6 +706,11 @@ retry3: ...@@ -711,6 +706,11 @@ retry3:
/* ready for read */ /* ready for read */
break; break;
default: default:
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext(
"server closed the connection unexpectedly\n"
"\tThis probably means the server terminated abnormally\n"
"\tbefore or while processing the request.\n"));
goto definitelyFailed; goto definitelyFailed;
} }
...@@ -739,11 +739,7 @@ retry4: ...@@ -739,11 +739,7 @@ retry4:
if (SOCK_ERRNO == ECONNRESET) if (SOCK_ERRNO == ECONNRESET)
goto definitelyFailed; goto definitelyFailed;
#endif #endif
/* in SSL mode, pqsecure_read set the error message */ /* pqsecure_read set the error message for us */
if (conn->ssl == NULL)
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not receive data from server: %s\n"),
SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
return -1; return -1;
} }
if (nread > 0) if (nread > 0)
...@@ -754,16 +750,10 @@ retry4: ...@@ -754,16 +750,10 @@ retry4:
/* /*
* OK, we are getting a zero read even though select() says ready. This * OK, we are getting a zero read even though select() says ready. This
* means the connection has been closed. Cope. * means the connection has been closed. Cope. Note that errorMessage
* has been set already.
*/ */
definitelyFailed: definitelyFailed:
/* in SSL mode, pqsecure_read set the error message */
if (conn->ssl == NULL)
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext(
"server closed the connection unexpectedly\n"
"\tThis probably means the server terminated abnormally\n"
"\tbefore or while processing the request.\n"));
conn->status = CONNECTION_BAD; /* No more connection to backend */ conn->status = CONNECTION_BAD; /* No more connection to backend */
pqsecure_close(conn); pqsecure_close(conn);
closesocket(conn->sock); closesocket(conn->sock);
...@@ -799,7 +789,6 @@ pqSendSome(PGconn *conn, int len) ...@@ -799,7 +789,6 @@ pqSendSome(PGconn *conn, int len)
while (len > 0) while (len > 0)
{ {
int sent; int sent;
char sebuf[256];
#ifndef WIN32 #ifndef WIN32
sent = pqsecure_write(conn, ptr, len); sent = pqsecure_write(conn, ptr, len);
...@@ -815,11 +804,7 @@ pqSendSome(PGconn *conn, int len) ...@@ -815,11 +804,7 @@ pqSendSome(PGconn *conn, int len)
if (sent < 0) if (sent < 0)
{ {
/* /* Anything except EAGAIN/EWOULDBLOCK/EINTR is trouble */
* Anything except EAGAIN/EWOULDBLOCK/EINTR is trouble. If it's
* EPIPE or ECONNRESET, assume we've lost the backend connection
* permanently.
*/
switch (SOCK_ERRNO) switch (SOCK_ERRNO)
{ {
#ifdef EAGAIN #ifdef EAGAIN
...@@ -833,17 +818,8 @@ pqSendSome(PGconn *conn, int len) ...@@ -833,17 +818,8 @@ pqSendSome(PGconn *conn, int len)
case EINTR: case EINTR:
continue; continue;
case EPIPE: default:
#ifdef ECONNRESET /* pqsecure_write set the error message for us */
case ECONNRESET:
#endif
/* in SSL mode, pqsecure_write set the error message */
if (conn->ssl == NULL)
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext(
"server closed the connection unexpectedly\n"
"\tThis probably means the server terminated abnormally\n"
"\tbefore or while processing the request.\n"));
/* /*
* We used to close the socket here, but that's a bad idea * We used to close the socket here, but that's a bad idea
...@@ -855,16 +831,6 @@ pqSendSome(PGconn *conn, int len) ...@@ -855,16 +831,6 @@ pqSendSome(PGconn *conn, int len)
*/ */
conn->outCount = 0; conn->outCount = 0;
return -1; return -1;
default:
/* in SSL mode, pqsecure_write set the error message */
if (conn->ssl == NULL)
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not send data to server: %s\n"),
SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
/* We don't assume it's a fatal error... */
conn->outCount = 0;
return -1;
} }
} }
else else
......
This diff is collapsed.
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