libpq ASYNC with PQgetResult and PQisBusy - Mailing list pgsql-general

From Raimon Fernandez
Subject libpq ASYNC with PQgetResult and PQisBusy
Date
Msg-id 2F4AE0A3-673D-4CC4-8D35-D04FAB10F5FC@montx.com
Whole thread Raw
In response to Re: How to guard PostgreSQL from overcharged and/or malicious (read-only) queries?  (Alban Hertroys <dalroi@solfertje.student.utwente.nl>)
Responses Re: libpq ASYNC with PQgetResult and PQisBusy  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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
PQgetResultis null. 

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


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.

pgsql-general by date:

Previous
From: Alban Hertroys
Date:
Subject: Re: How to guard PostgreSQL from overcharged and/or malicious (read-only) queries?
Next
From: "Mark Watson"
Date:
Subject: Re: Copy From suggestion