@@ -578,7 +578,6 @@ pqReadData(PGconn *conn)
578578{
579579 int someread = 0 ;
580580 int nread ;
581- char sebuf [256 ];
582581
583582 if (conn -> sock < 0 )
584583 {
@@ -647,11 +646,7 @@ pqReadData(PGconn *conn)
647646 if (SOCK_ERRNO == ECONNRESET )
648647 goto definitelyFailed ;
649648#endif
650- /* in SSL mode, pqsecure_read set the error message */
651- if (conn -> ssl == NULL )
652- printfPQExpBuffer (& conn -> errorMessage ,
653- libpq_gettext ("could not receive data from server: %s\n" ),
654- SOCK_STRERROR (SOCK_ERRNO , sebuf , sizeof (sebuf )));
649+ /* pqsecure_read set the error message for us */
655650 return -1 ;
656651 }
657652 if (nread > 0 )
@@ -711,6 +706,11 @@ pqReadData(PGconn *conn)
711706 /* ready for read */
712707 break ;
713708 default :
709+ printfPQExpBuffer (& conn -> errorMessage ,
710+ libpq_gettext (
711+ "server closed the connection unexpectedly\n"
712+ "\tThis probably means the server terminated abnormally\n"
713+ "\tbefore or while processing the request.\n" ));
714714 goto definitelyFailed ;
715715 }
716716
@@ -739,11 +739,7 @@ pqReadData(PGconn *conn)
739739 if (SOCK_ERRNO == ECONNRESET )
740740 goto definitelyFailed ;
741741#endif
742- /* in SSL mode, pqsecure_read set the error message */
743- if (conn -> ssl == NULL )
744- printfPQExpBuffer (& conn -> errorMessage ,
745- libpq_gettext ("could not receive data from server: %s\n" ),
746- SOCK_STRERROR (SOCK_ERRNO , sebuf , sizeof (sebuf )));
742+ /* pqsecure_read set the error message for us */
747743 return -1 ;
748744 }
749745 if (nread > 0 )
@@ -754,16 +750,10 @@ pqReadData(PGconn *conn)
754750
755751 /*
756752 * OK, we are getting a zero read even though select() says ready. This
757- * means the connection has been closed. Cope.
753+ * means the connection has been closed. Cope. Note that errorMessage
754+ * has been set already.
758755 */
759756definitelyFailed :
760- /* in SSL mode, pqsecure_read set the error message */
761- if (conn -> ssl == NULL )
762- printfPQExpBuffer (& conn -> errorMessage ,
763- libpq_gettext (
764- "server closed the connection unexpectedly\n"
765- "\tThis probably means the server terminated abnormally\n"
766- "\tbefore or while processing the request.\n" ));
767757 conn -> status = CONNECTION_BAD ; /* No more connection to backend */
768758 pqsecure_close (conn );
769759 closesocket (conn -> sock );
@@ -799,7 +789,6 @@ pqSendSome(PGconn *conn, int len)
799789 while (len > 0 )
800790 {
801791 int sent ;
802- char sebuf [256 ];
803792
804793#ifndef WIN32
805794 sent = pqsecure_write (conn , ptr , len );
@@ -815,11 +804,7 @@ pqSendSome(PGconn *conn, int len)
815804
816805 if (sent < 0 )
817806 {
818- /*
819- * Anything except EAGAIN/EWOULDBLOCK/EINTR is trouble. If it's
820- * EPIPE or ECONNRESET, assume we've lost the backend connection
821- * permanently.
822- */
807+ /* Anything except EAGAIN/EWOULDBLOCK/EINTR is trouble */
823808 switch (SOCK_ERRNO )
824809 {
825810#ifdef EAGAIN
@@ -833,17 +818,8 @@ pqSendSome(PGconn *conn, int len)
833818 case EINTR :
834819 continue ;
835820
836- case EPIPE :
837- #ifdef ECONNRESET
838- case ECONNRESET :
839- #endif
840- /* in SSL mode, pqsecure_write set the error message */
841- if (conn -> ssl == NULL )
842- printfPQExpBuffer (& conn -> errorMessage ,
843- libpq_gettext (
844- "server closed the connection unexpectedly\n"
845- "\tThis probably means the server terminated abnormally\n"
846- "\tbefore or while processing the request.\n" ));
821+ default :
822+ /* pqsecure_write set the error message for us */
847823
848824 /*
849825 * We used to close the socket here, but that's a bad idea
@@ -855,16 +831,6 @@ pqSendSome(PGconn *conn, int len)
855831 */
856832 conn -> outCount = 0 ;
857833 return -1 ;
858-
859- default :
860- /* in SSL mode, pqsecure_write set the error message */
861- if (conn -> ssl == NULL )
862- printfPQExpBuffer (& conn -> errorMessage ,
863- libpq_gettext ("could not send data to server: %s\n" ),
864- SOCK_STRERROR (SOCK_ERRNO , sebuf , sizeof (sebuf )));
865- /* We don't assume it's a fatal error... */
866- conn -> outCount = 0 ;
867- return -1 ;
868834 }
869835 }
870836 else
0 commit comments