*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.110 2000/01/15 05:37:21 ishii Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.111 2000/01/16 21:18:52 tgl Exp $
*
*-------------------------------------------------------------------------
*/
static int
connectDBComplete(PGconn *conn)
{
- PostgresPollingStatusType flag;
+ PostgresPollingStatusType flag = PGRES_POLLING_WRITING;
+
+ if (conn == NULL || conn->status == CONNECTION_BAD)
+ return 0;
for (;;) {
- flag = PQconnectPoll(conn);
+ /*
+ * Wait, if necessary. Note that the initial state (just after
+ * PQconnectStart) is to wait for the socket to select for writing.
+ */
switch (flag)
{
case PGRES_POLLING_ACTIVE:
conn->status = CONNECTION_BAD;
return 0;
}
+ /*
+ * Now try to advance the state machine.
+ */
+ flag = PQconnectPoll(conn);
}
}
* Starts the process of passing the values of a standard set of environment
* variables to the backend.
*
- * ---------------- */
+ * ----------------
+ */
PGsetenvHandle
PQsetenvStart(PGconn *conn)
{
struct pg_setenv_state *handle;
+ if (conn == NULL || conn->status == CONNECTION_BAD)
+ return NULL;
+
if ((handle = malloc(sizeof(struct pg_setenv_state))) == NULL)
{
printfPQExpBuffer(&conn->errorMessage,
PQsetenv(PGconn *conn)
{
PGsetenvHandle handle;
- PostgresPollingStatusType flag;
+ PostgresPollingStatusType flag = PGRES_POLLING_WRITING;
if ((handle = PQsetenvStart(conn)) == NULL)
return 0;
for (;;) {
- flag = PQsetenvPoll(conn);
+ /*
+ * Wait, if necessary. Note that the initial state (just after
+ * PQsetenvStart) is to wait for the socket to select for writing.
+ */
switch (flag)
{
case PGRES_POLLING_ACTIVE:
break;
default:
- /* Just in case we failed to set it in PQconnectPoll */
+ /* Just in case we failed to set it in PQsetenvPoll */
conn->status = CONNECTION_BAD;
return 0;
}
+ /*
+ * Now try to advance the state machine.
+ */
+ flag = PQsetenvPoll(conn);
}
}