summaryrefslogtreecommitdiff
path: root/psycopg
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2019-03-07 23:07:27 +0000
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2019-03-16 20:05:40 +0000
commite864050d079e818e34aa72e6093292170f95a2cc (patch)
tree87c87667da110b523a7db3f156c591ce72b9b483 /psycopg
parent2a8fa4bef7c71b1bec99ffdeaa7501d97ab11a57 (diff)
downloadpsycopg2-e864050d079e818e34aa72e6093292170f95a2cc.tar.gz
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.
Diffstat (limited to 'psycopg')
-rw-r--r--psycopg/connection_int.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c
index 7b563c5..3c7dc21 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: