diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2011-07-24 23:29:15 -0400 | 
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2011-07-24 23:29:15 -0400 | 
| commit | 65c033cbe913972872a10b17deae636243ae96df (patch) | |
| tree | bbb452ea99a39faf6ae8063926070226401231a3 /src/interfaces/libpq/fe-misc.c | |
| parent | 77e4fd5c4a500a4e6b24076c83bee17f55690831 (diff) | |
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.
Diffstat (limited to 'src/interfaces/libpq/fe-misc.c')
| -rw-r--r-- | src/interfaces/libpq/fe-misc.c | 58 | 
1 files changed, 12 insertions, 46 deletions
diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c index 0c5c90ed895..639823037a2 100644 --- a/src/interfaces/libpq/fe-misc.c +++ b/src/interfaces/libpq/fe-misc.c @@ -570,7 +570,6 @@ pqReadData(PGconn *conn)  {  	int			someread = 0;  	int			nread; -	char		sebuf[256];  	if (conn->sock < 0)  	{ @@ -639,11 +638,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) @@ -703,6 +698,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;  	} @@ -731,11 +731,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) @@ -746,16 +742,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); @@ -791,7 +781,6 @@ pqSendSome(PGconn *conn, int len)  	while (len > 0)  	{  		int			sent; -		char		sebuf[256];  #ifndef WIN32  		sent = pqsecure_write(conn, ptr, len); @@ -807,11 +796,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 @@ -825,17 +810,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 @@ -847,16 +823,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  | 
