mirror of
https://github.com/postgres/postgres.git
synced 2025-06-26 12:21:12 +03:00
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.
This commit is contained in:
@ -578,7 +578,6 @@ pqReadData(PGconn *conn)
|
||||
{
|
||||
int someread = 0;
|
||||
int nread;
|
||||
char sebuf[256];
|
||||
|
||||
if (conn->sock < 0)
|
||||
{
|
||||
@ -647,11 +646,7 @@ retry3:
|
||||
if (SOCK_ERRNO == ECONNRESET)
|
||||
goto definitelyFailed;
|
||||
#endif
|
||||
/* in SSL mode, pqsecure_read set the error message */
|
||||
if (conn->ssl == NULL)
|
||||
printfPQExpBuffer(&conn->errorMessage,
|
||||
libpq_gettext("could not receive data from server: %s\n"),
|
||||
SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
|
||||
/* pqsecure_read set the error message for us */
|
||||
return -1;
|
||||
}
|
||||
if (nread > 0)
|
||||
@ -711,6 +706,11 @@ retry3:
|
||||
/* ready for read */
|
||||
break;
|
||||
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;
|
||||
}
|
||||
|
||||
@ -739,11 +739,7 @@ retry4:
|
||||
if (SOCK_ERRNO == ECONNRESET)
|
||||
goto definitelyFailed;
|
||||
#endif
|
||||
/* in SSL mode, pqsecure_read set the error message */
|
||||
if (conn->ssl == NULL)
|
||||
printfPQExpBuffer(&conn->errorMessage,
|
||||
libpq_gettext("could not receive data from server: %s\n"),
|
||||
SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
|
||||
/* pqsecure_read set the error message for us */
|
||||
return -1;
|
||||
}
|
||||
if (nread > 0)
|
||||
@ -754,16 +750,10 @@ retry4:
|
||||
|
||||
/*
|
||||
* 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:
|
||||
/* 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 */
|
||||
pqsecure_close(conn);
|
||||
closesocket(conn->sock);
|
||||
@ -799,7 +789,6 @@ pqSendSome(PGconn *conn, int len)
|
||||
while (len > 0)
|
||||
{
|
||||
int sent;
|
||||
char sebuf[256];
|
||||
|
||||
#ifndef WIN32
|
||||
sent = pqsecure_write(conn, ptr, len);
|
||||
@ -815,11 +804,7 @@ pqSendSome(PGconn *conn, int len)
|
||||
|
||||
if (sent < 0)
|
||||
{
|
||||
/*
|
||||
* Anything except EAGAIN/EWOULDBLOCK/EINTR is trouble. If it's
|
||||
* EPIPE or ECONNRESET, assume we've lost the backend connection
|
||||
* permanently.
|
||||
*/
|
||||
/* Anything except EAGAIN/EWOULDBLOCK/EINTR is trouble */
|
||||
switch (SOCK_ERRNO)
|
||||
{
|
||||
#ifdef EAGAIN
|
||||
@ -833,17 +818,8 @@ pqSendSome(PGconn *conn, int len)
|
||||
case EINTR:
|
||||
continue;
|
||||
|
||||
case EPIPE:
|
||||
#ifdef ECONNRESET
|
||||
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"));
|
||||
default:
|
||||
/* pqsecure_write set the error message for us */
|
||||
|
||||
/*
|
||||
* We used to close the socket here, but that's a bad idea
|
||||
@ -855,16 +831,6 @@ pqSendSome(PGconn *conn, int len)
|
||||
*/
|
||||
conn->outCount = 0;
|
||||
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
|
||||
|
Reference in New Issue
Block a user