From e864050d079e818e34aa72e6093292170f95a2cc Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Thu, 7 Mar 2019 23:07:27 +0000 Subject: [PATCH] Simplified interactions between asyc functions Have advance_write calling flush itself, advance_read calling is_busy itself, rather than calling them in the caller and passing the result. Why we were doing the former on write I don't know. On read the paths between async and green function was different but they got unified in the previous commit. --- psycopg/connection_int.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c index 7b563c5c..3c7dc213 100644 --- a/psycopg/connection_int.c +++ b/psycopg/connection_int.c @@ -863,11 +863,16 @@ _conn_poll_connecting(connectionObject *self) /* Advance to the next state after an attempt of flushing output */ static int -_conn_poll_advance_write(connectionObject *self, int flush) +_conn_poll_advance_write(connectionObject *self) { int res; + int flush; Dprintf("conn_poll: poll writing"); + + flush = PQflush(self->pgconn); + Dprintf("conn_poll: PQflush() = %i", flush); + switch (flush) { case 0: /* success */ /* we've finished pushing the query to the server. Let's start @@ -893,11 +898,15 @@ _conn_poll_advance_write(connectionObject *self, int flush) /* Advance to the next state after a call to a pq_is_busy* function */ static int -_conn_poll_advance_read(connectionObject *self, int busy) +_conn_poll_advance_read(connectionObject *self) { int res; + int busy; Dprintf("conn_poll: poll reading"); + + busy = pq_is_busy(self); + switch (busy) { case 0: /* result is ready */ res = PSYCO_POLL_OK; @@ -931,18 +940,18 @@ _conn_poll_query(connectionObject *self) switch (self->async_status) { case ASYNC_WRITE: Dprintf("conn_poll: async_status = ASYNC_WRITE"); - res = _conn_poll_advance_write(self, PQflush(self->pgconn)); + res = _conn_poll_advance_write(self); break; case ASYNC_READ: Dprintf("conn_poll: async_status = ASYNC_READ"); - res = _conn_poll_advance_read(self, pq_is_busy(self)); + res = _conn_poll_advance_read(self); break; case ASYNC_DONE: Dprintf("conn_poll: async_status = ASYNC_DONE"); /* We haven't asked anything: just check for notifications. */ - res = _conn_poll_advance_read(self, pq_is_busy(self)); + res = _conn_poll_advance_read(self); break; default: