@@ -376,6 +376,10 @@ PostgresPollingStatusType *PQconnectPoll(PQconn *conn)
376
376
tested under Windows, and so it is currently off by default. This may be
377
377
changed in the future.
378
378
</para>
379
+ <para>
380
+ These functions leave the socket in a non-blocking state as if
381
+ <function>PQsetnonblocking</function> had been called.
382
+ </para>
379
383
<para>
380
384
These functions are not thread-safe.
381
385
</para>
@@ -1168,8 +1172,58 @@ discarded by <function>PQexec</function>.
1168
1172
Applications that do not like these limitations can instead use the
1169
1173
underlying functions that <function>PQexec</function> is built from:
1170
1174
<function>PQsendQuery</function> and <function>PQgetResult</function>.
1175
+ </para>
1176
+ <para>
1177
+ Older programs that used this functionality as well as
1178
+ <function>PQputline</function> and <function>PQputnbytes</function>
1179
+ could block waiting to send data to the backend, to
1180
+ address that issue, the function <function>PQsetnonblocking</function>
1181
+ was added.
1182
+ </para>
1183
+ <para>
1184
+ Old applications can neglect to use <function>PQsetnonblocking</function>
1185
+ and get the older potentially blocking behavior. Newer programs can use
1186
+ <function>PQsetnonblocking</function> to achieve a completely non-blocking
1187
+ connection to the backend.
1171
1188
1172
1189
<itemizedlist>
1190
+ <listitem>
1191
+ <para>
1192
+ <function>PQsetnonblocking</function> Sets the state of the connection
1193
+ to non-blocking.
1194
+ <synopsis>
1195
+ int PQsetnonblocking(PGconn *conn)
1196
+ </synopsis>
1197
+ this function will ensure that calls to
1198
+ <function>PQputline</function>, <function>PQputnbytes</function>,
1199
+ <function>PQsendQuery</function> and <function>PQendcopy</function>
1200
+ will not block but instead return an error if they need to be called
1201
+ again.
1202
+ </para>
1203
+ <para>
1204
+ When a database connection has been set to non-blocking mode and
1205
+ <function>PQexec</function> is called, it will temporarily set the state
1206
+ of the connection to blocking until the <function>PQexec</function>
1207
+ completes.
1208
+ </para>
1209
+ <para>
1210
+ More of libpq is expected to be made safe for
1211
+ <function>PQsetnonblocking</function> functionality in the near future.
1212
+ </para>
1213
+ </listitem>
1214
+
1215
+ <listitem>
1216
+ <para>
1217
+ <function>PQisnonblocking</function>
1218
+ Returns the blocking status of the database connection.
1219
+ <synopsis>
1220
+ int PQisnonblocking(const PGconn *conn)
1221
+ </synopsis>
1222
+ Returns TRUE if the connection is set to non-blocking mode,
1223
+ FALSE if blocking.
1224
+ </para>
1225
+ </listitem>
1226
+
1173
1227
<listitem>
1174
1228
<para>
1175
1229
<function>PQsendQuery</function>
@@ -1265,23 +1319,46 @@ state will never end.
1265
1319
</para>
1266
1320
</listitem>
1267
1321
1322
+ <listitem>
1323
+ <para>
1324
+ <function>PQflush</function> Attempt to flush any data queued to the backend,
1325
+ returns 0 if successful (or if the send queue is empty) or EOF if it failed for
1326
+ some reason.
1327
+ <synopsis>
1328
+ int PQflush(PGconn *conn);
1329
+ </synopsis>
1330
+ <function>PQflush</function> needs to be called on a non-blocking connection
1331
+ before calling <function>select</function> to determine if a responce has
1332
+ arrived. If 0 is returned it ensures that there is no data queued to the
1333
+ backend that has not actually been sent. Only applications that have used
1334
+ <function>PQsetnonblocking</function> have a need for this.
1335
+ </para>
1336
+ </listitem>
1337
+
1268
1338
<listitem>
1269
1339
<para>
1270
1340
<function>PQsocket</function>
1271
1341
Obtain the file descriptor number for the backend connection socket.
1272
- A valid descriptor will be > = 0; a result of -1 indicates that
1342
+ A valid descriptor will be > = 0; a result of -1 indicates that
1273
1343
no backend connection is currently open.
1274
1344
<synopsis>
1275
1345
int PQsocket(const PGconn *conn);
1276
1346
</synopsis>
1277
1347
<function>PQsocket</function> should be used to obtain the backend socket descriptor
1278
1348
in preparation for executing <function>select</function>(2). This allows an
1279
- application to wait for either backend responses or other conditions.
1349
+ application using a blocking connection to wait for either backend responses or
1350
+ other conditions.
1280
1351
If the result of <function>select</function>(2) indicates that data can be read from
1281
1352
the backend socket, then <function>PQconsumeInput</function> should be called to read the
1282
1353
data; after which, <function>PQisBusy</function>, <function>PQgetResult</function>,
1283
1354
and/or <function>PQnotifies</function> can be used to process the response.
1284
1355
</para>
1356
+ <para>
1357
+ Non-blocking connections (that have used <function>PQsetnonblocking</function>)
1358
+ should not use <function>select</function> until <function>PQflush</function>
1359
+ has returned 0 indicating that there is no buffered data waiting to be sent
1360
+ to the backend.
1361
+ </para>
1285
1362
</listitem>
1286
1363
1287
1364
</itemizedlist>
0 commit comments