@@ -330,8 +330,8 @@ PostgresPollingStatusType PQconnectPoll(PGconn *conn);
330
330
socket underlying the database connection.
331
331
Loop thus: If <function>PQconnectPoll(conn)</function> last returned
332
332
<symbol>PGRES_POLLING_READING</symbol>, wait until the socket is ready to
333
- read (as indicated by <function>select ()</>, <function>poll()</>, or
334
- similar system function).
333
+ read (as indicated by <function>PQselect ()</> or
334
+ < function>PQselectExtended()</> ).
335
335
Then call <function>PQconnectPoll(conn)</function> again.
336
336
Conversely, if <function>PQconnectPoll(conn)</function> last returned
337
337
<symbol>PGRES_POLLING_WRITING</symbol>, wait until the socket is ready
@@ -1943,6 +1943,42 @@ int PQsocket(const PGconn *conn);
1943
1943
</listitem>
1944
1944
</varlistentry>
1945
1945
1946
+ <varlistentry id="libpq-pqselect">
1947
+ <term><function>PQselect</function><indexterm><primary>PQselect</></></term>
1948
+ <listitem>
1949
+ <para>
1950
+ Uses select(2) to monitor multiple file descriptors, waiting until one or
1951
+ more of the file descriptors become "ready" for some class of I/O
1952
+ operation (e.g., input possible).
1953
+
1954
+ <synopsis>
1955
+ int PQselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout, int isRsocket);
1956
+ </synopsis>
1957
+
1958
+ </para>
1959
+ </listitem>
1960
+ </varlistentry>
1961
+
1962
+ <varlistentry id="libpq-pqselectextended">
1963
+ <term><function>PQselectExtended</function><indexterm><primary>PQselectExtended</></></term>
1964
+ <listitem>
1965
+ <para>
1966
+ Uses select(2) or poll(2) to wait for input. The <literal>timeout</>
1967
+ argument specifies the number of milliseconds that
1968
+ <function>PQselectExtended</> should block waiting for a file descriptor
1969
+ of the connection to become ready. Specifying a negative value
1970
+ in <literal>timeout</> means an infinite timeout. Specifying a
1971
+ <literal>timeout</> of zero causes <function>poll()</> to return
1972
+ immediately.
1973
+
1974
+ <synopsis>
1975
+ int PQselectExtended(const PGconn *conn, int timeout_ms);
1976
+ </synopsis>
1977
+
1978
+ </para>
1979
+ </listitem>
1980
+ </varlistentry>
1981
+
1946
1982
<varlistentry id="libpq-pqbackendpid">
1947
1983
<term><function>PQbackendPID</function><indexterm><primary>PQbackendPID</></></term>
1948
1984
<listitem>
@@ -4558,10 +4594,10 @@ int PQconsumeInput(PGconn *conn);
4558
4594
<function>PQconsumeInput</function> can be called even if the
4559
4595
application is not prepared to deal with a result or notification
4560
4596
just yet. The function will read available data and save it in
4561
- a buffer, thereby causing a <function>select ()</function>
4597
+ a buffer, thereby causing a <function>PQselect ()</function>
4562
4598
read-ready indication to go away. The application can thus use
4563
4599
<function>PQconsumeInput</function> to clear the
4564
- <function>select ()</function> condition immediately, and then
4600
+ <function>PQselect ()</function> condition immediately, and then
4565
4601
examine the results at leisure.
4566
4602
</para>
4567
4603
</listitem>
@@ -4598,10 +4634,10 @@ int PQisBusy(PGconn *conn);
4598
4634
4599
4635
<para>
4600
4636
A typical application using these functions will have a main loop that
4601
- uses <function>select ()</function> or <function>poll ()</> to wait for
4637
+ uses <function>PQselect ()</function> or <function>PQselectExtended ()</> to wait for
4602
4638
all the conditions that it must respond to. One of the conditions
4603
4639
will be input available from the server, which in terms of
4604
- <function>select ()</function> means readable data on the file
4640
+ <function>PQselect ()</function> means readable data on the file
4605
4641
descriptor identified by <function>PQsocket</function>. When the main
4606
4642
loop detects input ready, it should call
4607
4643
<function>PQconsumeInput</function> to read the input. It can then
@@ -5148,10 +5184,11 @@ typedef struct pgNotify
5148
5184
useful commands to execute is to call
5149
5185
<function>PQconsumeInput</function>, then check
5150
5186
<function>PQnotifies</function>. You can use
5151
- <function>select()</function> to wait for data to arrive from the
5187
+ <function>PQselect()</function> or <function>PQselectExtended()</function>
5188
+ to wait for data to arrive from the
5152
5189
server, thereby using no <acronym>CPU</acronym> power unless there is
5153
5190
something to do. (See <function>PQsocket</function> to obtain the file
5154
- descriptor number to use with <function>select ()</function>.) Note that
5191
+ descriptor number to use with <function>PQselect ()</function>.) Note that
5155
5192
this will work OK whether you submit commands with
5156
5193
<function>PQsendQuery</function>/<function>PQgetResult</function> or
5157
5194
simply use <function>PQexec</function>. You should, however, remember
@@ -8457,12 +8494,10 @@ main(int argc, char **argv)
8457
8494
while (nnotifies < 4)
8458
8495
{
8459
8496
/*
8460
- * Sleep until something happens on the connection. We use select(2)
8461
- * to wait for input, but you could also use poll() or similar
8462
- * facilities.
8497
+ * Sleep until something happens on the connection. We use
8498
+ * PQselectExtended to wait for input.
8463
8499
*/
8464
8500
int sock;
8465
- fd_set input_mask;
8466
8501
8467
8502
sock = PQsocket(conn);
8468
8503
@@ -8472,9 +8507,9 @@ main(int argc, char **argv)
8472
8507
FD_ZERO(&input_mask);
8473
8508
FD_SET(sock, &input_mask);
8474
8509
8475
- if (select(sock + 1, &input_mask, NULL, NULL, NULL ) < 0)
8510
+ if (PQselectExtended(conn, -1 ) < 0)
8476
8511
{
8477
- fprintf(stderr, "select () failed: %s\n", strerror(errno));
8512
+ fprintf(stderr, "PQselectExtended () failed: %s\n", strerror(errno));
8478
8513
exit_nicely(conn);
8479
8514
}
8480
8515
0 commit comments