Re: libpq ASYNC with PQgetResult and PQisBusy

From: Raimon Fernandez <coder(at)montx(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general List <pgsql-general(at)postgresql(dot)org>
Subject: Re: libpq ASYNC with PQgetResult and PQisBusy
Date: 2010-12-21 09:06:28
Message-ID: A3D294DB-331C-43AF-91AC-39A2ABA3F182@montx.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

hi again,

On 20dic, 2010, at 18:48 , Tom Lane wrote:

>> 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.
>
> Your proposed code is still a busy-wait loop. What you should be doing
> is waiting for some data to arrive on the socket. Once you see
> read-ready on the socket, call PQconsumeInput, then check PQisBusy to
> see if the query is complete or not. If not, go back to waiting on the
> socket. Typically you'd use select() or poll() to watch for both data
> on libpq's socket and whatever other events your app is interested in.

As I'm doing this as an excercise and how knows, I'm still playing with my previous approach, the same question but in a different way:

Why the PQisBusy is telling me that it's still busy if I send the PQgetResult and obtain them at the same moment ?

Now I'm not in a loop, just send the PQsendQuery from a button, and then, I just click on another button that simply checks for the PQconsumeInput and PQisBusy, and I'm clickin on it each second, and always it's returning busy, but if I send the PQgetResult I get it.

So, why libpq it's not updating it's status ?

thanks again,

r.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dario Beraldi 2010-12-21 09:14:36 Can the query planner create indexes?
Previous Message Raimon Fernandez 2010-12-21 07:11:45 Re: libpq ASYNC with PQgetResult and PQisBusy