Added pq_set_non_blocking utility function.

This commit is contained in:
Daniele Varrazzo 2010-04-07 19:04:42 +01:00
parent d339466c6a
commit 7e0dcfdda5
3 changed files with 25 additions and 3 deletions

View File

@ -317,9 +317,7 @@ conn_sync_connect(connectionObject *self)
if (conn_setup(self, pgconn) == -1)
return -1;
if (PQsetnonblocking(pgconn, 1) != 0) {
Dprintf("conn_connect: PQsetnonblocking() FAILED");
PyErr_SetString(OperationalError, "PQsetnonblocking() failed");
if (pq_set_non_blocking(self, 1, 1) != 0) {
return -1;
}

View File

@ -303,6 +303,29 @@ pq_clear_async(connectionObject *conn)
conn->async_cursor = NULL;
}
/* pq_set_non_blocking - set the nonblocking status on a connection.
Accepted arg values are 1 (nonblocking) and 0 (blocking).
Return 0 if everything ok, else nonzero.
In case of error, if pyerr is nonzero, set a Python exception.
*/
int
pq_set_non_blocking(connectionObject *conn, int arg, int pyerr)
{
int ret = PQsetnonblocking(conn->pgconn, arg);
if (0 != ret) {
Dprintf("PQsetnonblocking(%d) FAILED", arg);
if (pyerr) {
PyErr_SetString(OperationalError, "PQsetnonblocking() failed");
}
}
return ret;
}
/* pg_execute_command_locked - execute a no-result query on a locked connection.
This function should only be called on a locked connection without

View File

@ -47,6 +47,7 @@ HIDDEN int pq_reset(connectionObject *conn);
HIDDEN int pq_is_busy(connectionObject *conn);
HIDDEN int pq_flush(connectionObject *conn);
HIDDEN void pq_clear_async(connectionObject *conn);
HIDDEN int pq_set_non_blocking(connectionObject *conn, int arg, int pyerr);
HIDDEN void pq_set_critical(connectionObject *conn, const char *msg);