From 75a0299a485b2d3c85fd0a161931c9ca33e0e9c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Urba=C5=84ski?= Date: Fri, 26 Mar 2010 03:39:56 +0100 Subject: [PATCH] Add pq_flush, a function to flush the output buffer --- psycopg/pqpath.c | 34 ++++++++++++++++++++++++++++++---- psycopg/pqpath.h | 1 + 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/psycopg/pqpath.c b/psycopg/pqpath.c index c332160a..78b81d23 100644 --- a/psycopg/pqpath.c +++ b/psycopg/pqpath.c @@ -612,20 +612,46 @@ pq_is_busy(connectionObject *conn) PyTuple_SET_ITEM(notify, 1, PyString_FromString(pgn->relname)); PyList_Append(conn->notifies, notify); Py_UNBLOCK_THREADS; - free(pgn); + PQfreemem(pgn); } res = PQisBusy(conn->pgconn); - + pthread_mutex_unlock(&(conn->lock)); Py_END_ALLOW_THREADS; - + conn_notice_process(conn); return res; } -/* pq_execute - execute a query, possibly asyncronously + +/* pq_flush - flush output and return connection status + + a status of 1 means that a some data is still pending to be flushed, while a + status of 0 means that there is no data waiting to be sent. -1 means an + error and an exception will be set accordingly. + + this function locks the connection object + this function call Py_*_ALLOW_THREADS macros */ + +int +pq_flush(connectionObject *conn) +{ + int res; + + Dprintf("pq_flush: flushing output"); + + Py_BEGIN_ALLOW_THREADS; + pthread_mutex_lock(&(conn->lock)); + res = PQflush(conn->pgconn); + pthread_mutex_unlock(&(conn->lock)); + Py_END_ALLOW_THREADS; + + return res; +} + +/* pq_execute - execute a query, possibly asynchronously this fucntion locks the connection object this function call Py_*_ALLOW_THREADS macros */ diff --git a/psycopg/pqpath.h b/psycopg/pqpath.h index 89f6e57d..feca8b33 100644 --- a/psycopg/pqpath.h +++ b/psycopg/pqpath.h @@ -45,6 +45,7 @@ HIDDEN int pq_abort_locked(connectionObject *conn, PGresult **pgres, HIDDEN int pq_abort(connectionObject *conn); 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 void pq_set_critical(connectionObject *conn, const char *msg);