@@ -556,7 +556,6 @@ pqReadData(PGconn *conn)
556556{
557557 int someread = 0 ;
558558 int nread ;
559- char sebuf [256 ];
560559
561560 if (conn -> sock < 0 )
562561 {
@@ -625,11 +624,7 @@ pqReadData(PGconn *conn)
625624 if (SOCK_ERRNO == ECONNRESET )
626625 goto definitelyFailed ;
627626#endif
628- /* in SSL mode, pqsecure_read set the error message */
629- if (conn -> ssl == NULL )
630- printfPQExpBuffer (& conn -> errorMessage ,
631- libpq_gettext ("could not receive data from server: %s\n" ),
632- SOCK_STRERROR (SOCK_ERRNO , sebuf , sizeof (sebuf )));
627+ /* pqsecure_read set the error message for us */
633628 return -1 ;
634629 }
635630 if (nread > 0 )
@@ -689,6 +684,11 @@ pqReadData(PGconn *conn)
689684 /* ready for read */
690685 break ;
691686 default :
687+ printfPQExpBuffer (& conn -> errorMessage ,
688+ libpq_gettext (
689+ "server closed the connection unexpectedly\n"
690+ "\tThis probably means the server terminated abnormally\n"
691+ "\tbefore or while processing the request.\n" ));
692692 goto definitelyFailed ;
693693 }
694694
@@ -717,11 +717,7 @@ pqReadData(PGconn *conn)
717717 if (SOCK_ERRNO == ECONNRESET )
718718 goto definitelyFailed ;
719719#endif
720- /* in SSL mode, pqsecure_read set the error message */
721- if (conn -> ssl == NULL )
722- printfPQExpBuffer (& conn -> errorMessage ,
723- libpq_gettext ("could not receive data from server: %s\n" ),
724- SOCK_STRERROR (SOCK_ERRNO , sebuf , sizeof (sebuf )));
720+ /* pqsecure_read set the error message for us */
725721 return -1 ;
726722 }
727723 if (nread > 0 )
@@ -732,16 +728,10 @@ pqReadData(PGconn *conn)
732728
733729 /*
734730 * OK, we are getting a zero read even though select() says ready. This
735- * means the connection has been closed. Cope.
731+ * means the connection has been closed. Cope. Note that errorMessage
732+ * has been set already.
736733 */
737734definitelyFailed :
738- /* in SSL mode, pqsecure_read set the error message */
739- if (conn -> ssl == NULL )
740- printfPQExpBuffer (& conn -> errorMessage ,
741- libpq_gettext (
742- "server closed the connection unexpectedly\n"
743- "\tThis probably means the server terminated abnormally\n"
744- "\tbefore or while processing the request.\n" ));
745735 conn -> status = CONNECTION_BAD ; /* No more connection to backend */
746736 pqsecure_close (conn );
747737 closesocket (conn -> sock );
@@ -777,7 +767,6 @@ pqSendSome(PGconn *conn, int len)
777767 while (len > 0 )
778768 {
779769 int sent ;
780- char sebuf [256 ];
781770
782771#ifndef WIN32
783772 sent = pqsecure_write (conn , ptr , len );
@@ -792,11 +781,7 @@ pqSendSome(PGconn *conn, int len)
792781
793782 if (sent < 0 )
794783 {
795- /*
796- * Anything except EAGAIN/EWOULDBLOCK/EINTR is trouble. If it's
797- * EPIPE or ECONNRESET, assume we've lost the backend connection
798- * permanently.
799- */
784+ /* Anything except EAGAIN/EWOULDBLOCK/EINTR is trouble */
800785 switch (SOCK_ERRNO )
801786 {
802787#ifdef EAGAIN
@@ -810,17 +795,8 @@ pqSendSome(PGconn *conn, int len)
810795 case EINTR :
811796 continue ;
812797
813- case EPIPE :
814- #ifdef ECONNRESET
815- case ECONNRESET :
816- #endif
817- /* in SSL mode, pqsecure_write set the error message */
818- if (conn -> ssl == NULL )
819- printfPQExpBuffer (& conn -> errorMessage ,
820- libpq_gettext (
821- "server closed the connection unexpectedly\n"
822- "\tThis probably means the server terminated abnormally\n"
823- "\tbefore or while processing the request.\n" ));
798+ default :
799+ /* pqsecure_write set the error message for us */
824800
825801 /*
826802 * We used to close the socket here, but that's a bad idea
@@ -832,16 +808,6 @@ pqSendSome(PGconn *conn, int len)
832808 */
833809 conn -> outCount = 0 ;
834810 return -1 ;
835-
836- default :
837- /* in SSL mode, pqsecure_write set the error message */
838- if (conn -> ssl == NULL )
839- printfPQExpBuffer (& conn -> errorMessage ,
840- libpq_gettext ("could not send data to server: %s\n" ),
841- SOCK_STRERROR (SOCK_ERRNO , sebuf , sizeof (sebuf )));
842- /* We don't assume it's a fatal error... */
843- conn -> outCount = 0 ;
844- return -1 ;
845811 }
846812 }
847813 else
0 commit comments