From 0da4befe786679c557ef4ae52db486d704fc818d Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Thu, 22 Apr 2010 17:59:08 +0100 Subject: [PATCH] Added function to advance the state after flush attempt. --- psycopg/connection_int.c | 45 ++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c index e1670e45..f3982380 100644 --- a/psycopg/connection_int.c +++ b/psycopg/connection_int.c @@ -791,6 +791,35 @@ _conn_poll_connecting(connectionObject *self) } +/* Advance to the next state after an attempt of flushing output */ +int +_conn_poll_advance_write(connectionObject *self, int flush) +{ + int res; + + switch (flush) { + case 0: /* success */ + /* we've finished pushing the query to the server. Let's start + reading the results. */ + Dprintf("conn_poll: async_status -> ASYNC_READ"); + self->async_status = ASYNC_READ; + res = PSYCO_POLL_READ; + break; + case 1: /* would block */ + res = PSYCO_POLL_WRITE; + break; + case -1: /* error */ + PyErr_SetString(OperationalError, PQerrorMessage(self->pgconn)); + res = PSYCO_POLL_ERROR; + break; + default: + Dprintf("conn_poll: unexpected result from flush: %d", flush); + res = PSYCO_POLL_ERROR; + break; + } + return res; +} + /* Advance to the next state after a call to a pq_is_busy* function */ int _conn_poll_advance_read(connectionObject *self, int busy) @@ -829,21 +858,7 @@ _conn_poll_query(connectionObject *self) switch (self->async_status) { case ASYNC_WRITE: Dprintf("conn_poll: async_status = ASYNC_WRITE"); - switch (PQflush(self->pgconn)) { - case 0: /* success */ - /* we've finished pushing the query to the server. Let's start - reading the results. */ - self->async_status = ASYNC_READ; - res = PSYCO_POLL_READ; - break; - case 1: /* would block */ - res = PSYCO_POLL_WRITE; - break; - case -1: /* error */ - PyErr_SetString(OperationalError, PQerrorMessage(self->pgconn)); - res = PSYCO_POLL_ERROR; - break; - } + res = _conn_poll_advance_write(self, PQflush(self->pgconn)); break; case ASYNC_READ: