<symbol>CONNECTION_BAD</symbol>, <function>PQconnectStart</function> has failed.
<symbol>CONNECTION_BAD</symbol>, <function>PQconnectStart</function> has failed.
</para>
</para>
<para>
<para>
If <function>PQconnectStart</> succeeds, the next stage is to poll <application>libpq</> so that it may
If <function>PQconnectStart</> succeeds, the next stage is to poll
proceed with the connection sequence. Loop thus: If <function>PQconnectPoll(conn)</function> last returned
<application>libpq</> so that it may proceed with the connection sequence.
<symbol>PGRES_POLLING_READING</symbol>, perform a <function>select()</> for reading on the socket determined using <function>PQsocket(conn)</function>. If
Use <function>PQsocket(conn)</function> to obtain the descriptor of the
it last returned <symbol>PGRES_POLLING_WRITING</symbol>, perform a <function>select()</> for writing on
socket underlying the database connection.
that same socket. If you have yet to call <function>PQconnectPoll</function>, i.e., after the call
Loop thus: If <function>PQconnectPoll(conn)</function> last returned
to <function>PQconnectStart</function>, behave as if it last returned <symbol>PGRES_POLLING_WRITING</symbol>. If
<symbol>PGRES_POLLING_READING</symbol>, wait until the socket is ready to
<function>select()</> shows that the socket is ready, consider it <quote>active</quote>. If it has
read (as indicated by <function>select()</>, <function>poll()</>, or
been decided that this connection is <quote>active</quote>, call <function>PQconnectPoll(conn)</function>
similar system function).
again. If this call returns <symbol>PGRES_POLLING_FAILED</symbol>, the connection procedure
Then call <function>PQconnectPoll(conn)</function> again.
has failed. If this call returns <symbol>PGRES_POLLING_OK</symbol>, the connection has been
Conversely, if <function>PQconnectPoll(conn)</function> last returned
successfully made.
<symbol>PGRES_POLLING_WRITING</symbol>, wait until the socket is ready
</para>
to write, then call <function>PQconnectPoll(conn)</function> again.
If you have yet to call
<para>
<function>PQconnectPoll</function>, i.e., just after the call to
Note that the use of <function>select()</function> to ensure that the socket is ready is merely
<function>PQconnectStart</function>, behave as if it last returned
a (likely) example; those with other facilities available, such as a
<symbol>PGRES_POLLING_WRITING</symbol>. Continue this loop until
<function>poll()</function> call, may of course use that instead.
<function>PQconnectPoll(conn)</function> returns
<symbol>PGRES_POLLING_FAILED</symbol>, indicating the connection procedure
has failed, or <symbol>PGRES_POLLING_OK</symbol>, indicating the connection
has been successfully made.
</para>
</para>
<para>
<para>
At any time during connection, the status of the connection may be
At any time during connection, the status of the connection may be
checked, by calling <function>PQstatus</>. If this gives <symbol>CONNECTION_BAD</>, then the
checked by calling <function>PQstatus</>. If this gives <symbol>CONNECTION_BAD</>, then the
connection procedure has failed; if it gives <function>CONNECTION_OK</>, then the
connection procedure has failed; if it gives <function>CONNECTION_OK</>, then the
connection is ready. Both of these states are equally detectable
connection is ready. Both of these states are equally detectable
from the return value of <function>PQconnectPoll</>, described above. Other states may also occur
from the return value of <function>PQconnectPoll</>, described above. Other states may also occur