From 10d7287ab927214607e34bae1c4a0f7bad79a4aa Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Tue, 18 Jan 2000 06:09:24 +0000 Subject: Libpq non-blocking mode, from Alfred Perlstein --- doc/src/sgml/libpq.sgml | 81 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 2 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/libpq.sgml b/doc/src/sgml/libpq.sgml index 290236e8b65..b6ba22e5678 100644 --- a/doc/src/sgml/libpq.sgml +++ b/doc/src/sgml/libpq.sgml @@ -376,6 +376,10 @@ PostgresPollingStatusType *PQconnectPoll(PQconn *conn) tested under Windows, and so it is currently off by default. This may be changed in the future. + + These functions leave the socket in a non-blocking state as if + PQsetnonblocking had been called. + These functions are not thread-safe. @@ -1168,8 +1172,58 @@ discarded by PQexec. Applications that do not like these limitations can instead use the underlying functions that PQexec is built from: PQsendQuery and PQgetResult. + + +Older programs that used this functionality as well as +PQputline and PQputnbytes +could block waiting to send data to the backend, to +address that issue, the function PQsetnonblocking +was added. + + +Old applications can neglect to use PQsetnonblocking +and get the older potentially blocking behavior. Newer programs can use +PQsetnonblocking to achieve a completely non-blocking +connection to the backend. + + + PQsetnonblocking Sets the state of the connection + to non-blocking. + +int PQsetnonblocking(PGconn *conn) + + this function will ensure that calls to + PQputline, PQputnbytes, + PQsendQuery and PQendcopy + will not block but instead return an error if they need to be called + again. + + + When a database connection has been set to non-blocking mode and + PQexec is called, it will temporarily set the state + of the connection to blocking until the PQexec + completes. + + + More of libpq is expected to be made safe for + PQsetnonblocking functionality in the near future. + + + + + +PQisnonblocking + Returns the blocking status of the database connection. + +int PQisnonblocking(const PGconn *conn) + + Returns TRUE if the connection is set to non-blocking mode, + FALSE if blocking. + + + PQsendQuery @@ -1265,23 +1319,46 @@ state will never end. + + +PQflush Attempt to flush any data queued to the backend, +returns 0 if successful (or if the send queue is empty) or EOF if it failed for +some reason. + +int PQflush(PGconn *conn); + +PQflush needs to be called on a non-blocking connection +before calling select to determine if a responce has +arrived. If 0 is returned it ensures that there is no data queued to the +backend that has not actually been sent. Only applications that have used +PQsetnonblocking have a need for this. + + + PQsocket Obtain the file descriptor number for the backend connection socket. - A valid descriptor will be >= 0; a result of -1 indicates that + A valid descriptor will be >= 0; a result of -1 indicates that no backend connection is currently open. int PQsocket(const PGconn *conn); PQsocket should be used to obtain the backend socket descriptor in preparation for executing select(2). This allows an -application to wait for either backend responses or other conditions. +application using a blocking connection to wait for either backend responses or +other conditions. If the result of select(2) indicates that data can be read from the backend socket, then PQconsumeInput should be called to read the data; after which, PQisBusy, PQgetResult, and/or PQnotifies can be used to process the response. + +Non-blocking connections (that have used PQsetnonblocking) +should not use select until PQflush +has returned 0 indicating that there is no buffered data waiting to be sent +to the backend. + -- cgit v1.2.3