Home Explore Blog CI



postgresql

8th chunk of `doc/src/sgml/libpq.sgml`
7557242ce3cb46e6cfd381544f7efc6ec83f2427073977ad0000000100000fa3
 </para>

      <para>
       Note that when <function>PQconnectStart</function>
       or <xref linkend="libpq-PQconnectStartParams"/> returns a non-null
       pointer, you must call <xref linkend="libpq-PQfinish"/> when you are
       finished with it, in order to dispose of the structure and any
       associated memory blocks.  This must be done even if the connection
       attempt fails or is abandoned.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry id="libpq-PQsocketPoll">
     <term><function>PQsocketPoll</function><indexterm><primary>PQsocketPoll</primary></indexterm></term>
     <listitem>
      <para>
       <indexterm><primary>nonblocking connection</primary></indexterm>
       Poll a connection's underlying socket descriptor retrieved with
       <xref linkend="libpq-PQsocket"/>.
       The primary use of this function is iterating through the connection
       sequence described in the documentation of
       <xref linkend="libpq-PQconnectStartParams"/>.
<synopsis>
typedef int64_t pg_usec_time_t;

int PQsocketPoll(int sock, int forRead, int forWrite,
                 pg_usec_time_t end_time);
</synopsis>
      </para>

      <para>
       This function performs polling of a file descriptor, optionally with
       a timeout.
       If <parameter>forRead</parameter> is nonzero, the
       function will terminate when the socket is ready for
       reading. If <parameter>forWrite</parameter> is nonzero,
       the function will terminate when the
       socket is ready for writing.
      </para>

      <para>
       The timeout is specified by <parameter>end_time</parameter>, which
       is the time to stop waiting expressed as a number of microseconds since
       the Unix epoch (that is, <type>time_t</type> times 1 million).
       Timeout is infinite if <parameter>end_time</parameter>
       is <literal>-1</literal>.  Timeout is immediate (no blocking) if
       <parameter>end_time</parameter> is <literal>0</literal> (or indeed, any
       time before now).  Timeout values can be calculated conveniently by
       adding the desired number of microseconds to the result of
       <xref linkend="libpq-PQgetCurrentTimeUSec"/>.
       Note that the underlying system calls may have less than microsecond
       precision, so that the actual delay may be imprecise.
      </para>

      <para>
       The function returns a value greater than <literal>0</literal> if the
       specified condition is met, <literal>0</literal> if a timeout occurred,
       or <literal>-1</literal> if an error occurred. The error can be
       retrieved by checking the <literal>errno(3)</literal> value. In the
       event both <parameter>forRead</parameter>
       and <parameter>forWrite</parameter> are zero, the function immediately
       returns a timeout indication.
      </para>

      <para>
       <function>PQsocketPoll</function> is implemented using either
       <function>poll(2)</function> or <function>select(2)</function>,
       depending on platform.  See <literal>POLLIN</literal>
       and <literal>POLLOUT</literal> from <function>poll(2)</function>,
       or <parameter>readfds</parameter> and
       <parameter>writefds</parameter> from <function>select(2)</function>,
       for more information.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry id="libpq-PQconndefaults">
     <term><function>PQconndefaults</function><indexterm><primary>PQconndefaults</primary></indexterm></term>
     <listitem>
      <para>
       Returns the default connection options.
<synopsis>
PQconninfoOption *PQconndefaults(void);

typedef struct
{
    char   *keyword;   /* The keyword of the option */
    char   *envvar;    /* Fallback environment variable name */
    char   *compiled;  /* Fallback compiled in default value */
    char   *val;       /* Option's current value, or NULL */
    char   *label;     /* Label for field in connect dialog */
    char   *dispchar;  /* Indicates how to display this field

Title: PQsocketPoll: Polling a Connection's Socket Descriptor
Summary
This section focuses on the PQsocketPoll function, which allows polling a connection's underlying socket descriptor obtained via PQsocket. It's primarily used for iterating through the connection sequence in non-blocking connections. The function syntax is provided, detailing parameters for read and write readiness checks, as well as a timeout value specified in microseconds since the Unix epoch. The function returns a value indicating if the specified condition is met, a timeout occurred, or an error occurred, with errno providing further error details. PQsocketPoll is implemented using either poll(2) or select(2), depending on the platform.