@@ -1896,6 +1896,7 @@ PQconnectPoll(PGconn *conn)
1896
1896
case CONNECTION_SSL_STARTUP :
1897
1897
case CONNECTION_NEEDED :
1898
1898
case CONNECTION_CHECK_WRITABLE :
1899
+ case CONNECTION_CONSUME :
1899
1900
break ;
1900
1901
1901
1902
default :
@@ -2935,6 +2936,34 @@ PQconnectPoll(PGconn *conn)
2935
2936
conn -> status = CONNECTION_OK ;
2936
2937
return PGRES_POLLING_OK ;
2937
2938
2939
+ case CONNECTION_CONSUME :
2940
+ {
2941
+ conn -> status = CONNECTION_OK ;
2942
+ if (!PQconsumeInput (conn ))
2943
+ goto error_return ;
2944
+
2945
+ if (PQisBusy (conn ))
2946
+ {
2947
+ conn -> status = CONNECTION_CONSUME ;
2948
+ restoreErrorMessage (conn , & savedMessage );
2949
+ return PGRES_POLLING_READING ;
2950
+ }
2951
+
2952
+ /*
2953
+ * Call PQgetResult() again to consume NULL result.
2954
+ */
2955
+ res = PQgetResult (conn );
2956
+ if (res != NULL )
2957
+ {
2958
+ PQclear (res );
2959
+ conn -> status = CONNECTION_CONSUME ;
2960
+ goto keep_going ;
2961
+ }
2962
+
2963
+ /* We are open for business! */
2964
+ conn -> status = CONNECTION_OK ;
2965
+ return PGRES_POLLING_OK ;
2966
+ }
2938
2967
case CONNECTION_CHECK_WRITABLE :
2939
2968
{
2940
2969
if (!saveErrorMessage (conn , & savedMessage ))
@@ -2994,9 +3023,12 @@ PQconnectPoll(PGconn *conn)
2994
3023
/* We can release the address lists now. */
2995
3024
release_all_addrinfo (conn );
2996
3025
2997
- /* We are open for business! */
2998
- conn -> status = CONNECTION_OK ;
2999
- return PGRES_POLLING_OK ;
3026
+ /*
3027
+ * Finish reading any remaining messages before
3028
+ * being considered as ready.
3029
+ */
3030
+ conn -> status = CONNECTION_CONSUME ;
3031
+ goto keep_going ;
3000
3032
}
3001
3033
3002
3034
/*
0 commit comments