@ -24,6 +24,7 @@
# include "common/connect.h"
# include "common/connect.h"
# include "funcapi.h"
# include "funcapi.h"
# include "libpq-fe.h"
# include "libpq-fe.h"
# include "libpq/libpq-be-fe-helpers.h"
# include "mb/pg_wchar.h"
# include "mb/pg_wchar.h"
# include "miscadmin.h"
# include "miscadmin.h"
# include "pgstat.h"
# include "pgstat.h"
@ -125,7 +126,6 @@ libpqrcv_connect(const char *conninfo, bool logical, const char *appname,
char * * err )
char * * err )
{
{
WalReceiverConn * conn ;
WalReceiverConn * conn ;
PostgresPollingStatusType status ;
const char * keys [ 6 ] ;
const char * keys [ 6 ] ;
const char * vals [ 6 ] ;
const char * vals [ 6 ] ;
int i = 0 ;
int i = 0 ;
@ -172,50 +172,11 @@ libpqrcv_connect(const char *conninfo, bool logical, const char *appname,
Assert ( i < sizeof ( keys ) ) ;
Assert ( i < sizeof ( keys ) ) ;
conn = palloc0 ( sizeof ( WalReceiverConn ) ) ;
conn = palloc0 ( sizeof ( WalReceiverConn ) ) ;
conn - > streamConn = PQconnectStartParams ( keys , vals ,
conn - > streamConn =
/* expand_dbname = */ true ) ;
libpqsrv_connect_params ( keys , vals ,
if ( PQstatus ( conn - > streamConn ) = = CONNECTION_BAD )
/* expand_dbname = */ true ,
goto bad_connection_errmsg ;
/*
* Poll connection until we have OK or FAILED status .
*
* Per spec for PQconnectPoll , first wait till socket is write - ready .
*/
status = PGRES_POLLING_WRITING ;
do
{
int io_flag ;
int rc ;
if ( status = = PGRES_POLLING_READING )
io_flag = WL_SOCKET_READABLE ;
# ifdef WIN32
/* Windows needs a different test while waiting for connection-made */
else if ( PQstatus ( conn - > streamConn ) = = CONNECTION_STARTED )
io_flag = WL_SOCKET_CONNECTED ;
# endif
else
io_flag = WL_SOCKET_WRITEABLE ;
rc = WaitLatchOrSocket ( MyLatch ,
WL_EXIT_ON_PM_DEATH | WL_LATCH_SET | io_flag ,
PQsocket ( conn - > streamConn ) ,
0 ,
WAIT_EVENT_LIBPQWALRECEIVER_CONNECT ) ;
WAIT_EVENT_LIBPQWALRECEIVER_CONNECT ) ;
/* Interrupted? */
if ( rc & WL_LATCH_SET )
{
ResetLatch ( MyLatch ) ;
ProcessWalRcvInterrupts ( ) ;
}
/* If socket is ready, advance the libpq state machine */
if ( rc & io_flag )
status = PQconnectPoll ( conn - > streamConn ) ;
} while ( status ! = PGRES_POLLING_OK & & status ! = PGRES_POLLING_FAILED ) ;
if ( PQstatus ( conn - > streamConn ) ! = CONNECTION_OK )
if ( PQstatus ( conn - > streamConn ) ! = CONNECTION_OK )
goto bad_connection_errmsg ;
goto bad_connection_errmsg ;
@ -245,7 +206,7 @@ bad_connection_errmsg:
/* error path, error already set */
/* error path, error already set */
bad_connection :
bad_connection :
PQfinish ( conn - > streamConn ) ;
libpqsrv_disconnect ( conn - > streamConn ) ;
pfree ( conn ) ;
pfree ( conn ) ;
return NULL ;
return NULL ;
}
}
@ -744,7 +705,7 @@ libpqrcv_PQgetResult(PGconn *streamConn)
static void
static void
libpqrcv_disconnect ( WalReceiverConn * conn )
libpqrcv_disconnect ( WalReceiverConn * conn )
{
{
PQfinish ( conn - > streamConn ) ;
libpqsrv_disconnect ( conn - > streamConn ) ;
PQfreemem ( conn - > recvBuf ) ;
PQfreemem ( conn - > recvBuf ) ;
pfree ( conn ) ;
pfree ( conn ) ;
}
}