Commit e434ad39 authored by Peter Eisentraut's avatar Peter Eisentraut

Reorder the asynchronous libpq calls for replication connection

Per libpq documentation, the initial state must be
PGRES_POLLING_WRITING.  Failing to do that appears to cause some issues
on some Windows systems.

From: Petr Jelinek <petr.jelinek@2ndquadrant.com>
parent 6f3a13ff
...@@ -155,12 +155,16 @@ libpqrcv_connect(const char *conninfo, bool logical, const char *appname, ...@@ -155,12 +155,16 @@ libpqrcv_connect(const char *conninfo, bool logical, const char *appname,
return NULL; return NULL;
} }
/* Poll connection. */ /*
do * Poll connection until we have OK or FAILED status.
*
* Note that the initial state after PQconnectStartParams is
* PGRES_POLLING_WRITING.
*/
for (status = PGRES_POLLING_WRITING;
status != PGRES_POLLING_OK && status != PGRES_POLLING_FAILED;
status = PQconnectPoll(conn->streamConn))
{ {
/* Determine current state of the connection. */
status = PQconnectPoll(conn->streamConn);
/* Sleep a bit if waiting for socket. */ /* Sleep a bit if waiting for socket. */
if (status == PGRES_POLLING_READING || if (status == PGRES_POLLING_READING ||
status == PGRES_POLLING_WRITING) status == PGRES_POLLING_WRITING)
...@@ -188,9 +192,7 @@ libpqrcv_connect(const char *conninfo, bool logical, const char *appname, ...@@ -188,9 +192,7 @@ libpqrcv_connect(const char *conninfo, bool logical, const char *appname,
if (rc & WL_LATCH_SET) if (rc & WL_LATCH_SET)
CHECK_FOR_INTERRUPTS(); CHECK_FOR_INTERRUPTS();
} }
}
/* Otherwise loop until we have OK or FAILED status. */
} while (status != PGRES_POLLING_OK && status != PGRES_POLLING_FAILED);
if (PQstatus(conn->streamConn) != CONNECTION_OK) if (PQstatus(conn->streamConn) != CONNECTION_OK)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment