mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-11 03:26:37 +03:00
Added pq_set_non_blocking utility function.
This commit is contained in:
parent
d339466c6a
commit
7e0dcfdda5
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user