+
+
PQsocketPollPQsocketPoll
+
+ Poll a connection's underlying socket descriptor retrieved with .
+
+int PQsocketPoll(int sock, int forRead, int forWrite, time_t end_time);
+
+
+
+ This function sets up polling of a file descriptor. The underlying function is either
+ poll(2) or select(2), depending on platform
+ support. The primary use of this function is iterating through the connection sequence
+ described in the documentation of . If
+
forRead is specified, the function waits for the socket to be ready
+ for reading. If
forWrite is specified, the function waits for the
+ socket to be ready for write. See POLLIN and POLLOUT
+ from
poll(2), or
readfds and
+
writefds from
select(2) for more information. If
+
end_time is not
-1, it specifies the time at which
+ this function should stop waiting for the condition to be met.
+
+
+ The function returns a value greater than 0 if the specified condition
+ is met, 0 if a timeout occurred, or -1 if an error
+ occurred. The error can be retrieved by checking the errno(3) value. In
+ the event forRead and forWrite are not set, the
+ function immediately returns a timeout condition.
+
+
+
+
PQconnectStartParamsPQconnectStartParams
PQconnectStartPQconnectStart
Loop thus: If PQconnectPoll(conn) last returned
PGRES_POLLING_READING, wait until the socket is ready to
read (as indicated by select(), poll(), or
- similar system function).
+ similar system function). Note that PQsocketPoll
+ can help reduce boilerplate by abstracting the setup of
+ select(2) or poll(2) if it is
+ available on your system.
Then call PQconnectPoll(conn) again.
Conversely, if PQconnectPoll(conn) last returned
PGRES_POLLING_WRITING, wait until the socket is ready
static int pqSendSome(PGconn *conn, int len);
static int pqSocketCheck(PGconn *conn, int forRead, int forWrite,
time_t end_time);
-static int pqSocketPoll(int sock, int forRead, int forWrite, time_t end_time);
/*
* PQlibVersion: return the libpq version number
/* We will retry as long as we get EINTR */
do
- result = pqSocketPoll(conn->sock, forRead, forWrite, end_time);
+ result = PQsocketPoll(conn->sock, forRead, forWrite, end_time);
while (result < 0 && SOCK_ERRNO == EINTR);
if (result < 0)
* Timeout is infinite if end_time is -1. Timeout is immediate (no blocking)
* if end_time is 0 (or indeed, any time before now).
*/
-static int
-pqSocketPoll(int sock, int forRead, int forWrite, time_t end_time)
+int
+PQsocketPoll(int sock, int forRead, int forWrite, time_t end_time)
{
/* We use poll(2) if available, otherwise select(2) */
#ifdef HAVE_POLL
#endif
#include
+#include
/*
* postgres_ext.h defines the backend's externally visible types,
/* Get the version of the libpq library in use */
extern int PQlibVersion(void);
+/* Poll a socket for reading and/or writing with an optional timeout */
+extern int PQsocketPoll(int sock, int forRead, int forWrite, time_t end_time);
+
/* Determine length of multibyte encoded char at *s */
extern int PQmblen(const char *s, int encoding);