libpq ASYNC with PQgetResult and PQisBusy

From: Raimon Fernandez <coder(at)montx(dot)com>
To: pgsql-general List <pgsql-general(at)postgresql(dot)org>
Subject: libpq ASYNC with PQgetResult and PQisBusy
Date: 2010-12-20 13:19:41
Message-ID: 2F4AE0A3-673D-4CC4-8D35-D04FAB10F5FC@montx.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

I'm trying to create a plugin using the libpq.

Almost everything is working, and now I want to implememt the asynchronous issue.

I send the SQL using the PQsendQuery, and my interface is not blocking, great.

Now, everytime I check fot the PQgetResult my interface gets blocked.

So, now I'm using the PQisBusy to check if postgre is still busy and I can safely call the PQgetResult wihtout blocking, or just wait *some time* before sending a new PQisBusy.

Before every PQisBusy i call PQconsumeInput to update the status.

So, in pseudo code:

1. PQsendQuery (a really slow select just to check the asyncronous)

2. From a timer every 0.2 seconds, I call:
2.1 PQconsumeInput
2.2 PQisBusy
2.3 evaluate => if it's busy => sleep and start again from 2 ; if it's not busy, continue
2.4 call PQgetResult

Using PQisBusy it's not working, it's taking really longer to just send the 0 (non-busy) and at this moment the PQgetResult is null.

If I force to call the PQgetResult after just one second of the PQsendQuery I can get the PQgetResult, without testing the PQisBusy.

here is my montxPG_isBusy

static long montxPG_isBusy()

{ int execStatus;
int consumeeVar;

consumeeVar = PQconsumeInput(gPGconn);

if (consumeeVar == 0) return (long) PGRES_FATAL_ERROR;

execStatus = PQisBusy(gPGconn);

return (long) execStatus;

}

thanks,

regards,

r.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Mark Watson 2010-12-20 13:49:37 Re: Copy From suggestion
Previous Message Alban Hertroys 2010-12-20 11:43:38 Re: How to guard PostgreSQL from overcharged and/or malicious (read-only) queries?