mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-23 01:16:34 +03:00
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.
This commit is contained in:
parent
2a8fa4bef7
commit
e864050d07
|
@ -863,11 +863,16 @@ _conn_poll_connecting(connectionObject *self)
|
||||||
/* Advance to the next state after an attempt of flushing output */
|
/* Advance to the next state after an attempt of flushing output */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_conn_poll_advance_write(connectionObject *self, int flush)
|
_conn_poll_advance_write(connectionObject *self)
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
|
int flush;
|
||||||
|
|
||||||
Dprintf("conn_poll: poll writing");
|
Dprintf("conn_poll: poll writing");
|
||||||
|
|
||||||
|
flush = PQflush(self->pgconn);
|
||||||
|
Dprintf("conn_poll: PQflush() = %i", flush);
|
||||||
|
|
||||||
switch (flush) {
|
switch (flush) {
|
||||||
case 0: /* success */
|
case 0: /* success */
|
||||||
/* we've finished pushing the query to the server. Let's start
|
/* 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 */
|
/* Advance to the next state after a call to a pq_is_busy* function */
|
||||||
static int
|
static int
|
||||||
_conn_poll_advance_read(connectionObject *self, int busy)
|
_conn_poll_advance_read(connectionObject *self)
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
|
int busy;
|
||||||
|
|
||||||
Dprintf("conn_poll: poll reading");
|
Dprintf("conn_poll: poll reading");
|
||||||
|
|
||||||
|
busy = pq_is_busy(self);
|
||||||
|
|
||||||
switch (busy) {
|
switch (busy) {
|
||||||
case 0: /* result is ready */
|
case 0: /* result is ready */
|
||||||
res = PSYCO_POLL_OK;
|
res = PSYCO_POLL_OK;
|
||||||
|
@ -931,18 +940,18 @@ _conn_poll_query(connectionObject *self)
|
||||||
switch (self->async_status) {
|
switch (self->async_status) {
|
||||||
case ASYNC_WRITE:
|
case ASYNC_WRITE:
|
||||||
Dprintf("conn_poll: async_status = 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;
|
break;
|
||||||
|
|
||||||
case ASYNC_READ:
|
case ASYNC_READ:
|
||||||
Dprintf("conn_poll: async_status = 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;
|
break;
|
||||||
|
|
||||||
case ASYNC_DONE:
|
case ASYNC_DONE:
|
||||||
Dprintf("conn_poll: async_status = ASYNC_DONE");
|
Dprintf("conn_poll: async_status = ASYNC_DONE");
|
||||||
/* We haven't asked anything: just check for notifications. */
|
/* 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;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user