Re: libpq ASYNC with PQgetResult and PQisBusy

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: libpq ASYNC with PQgetResult and PQisBusy
Дата
Msg-id 11518.1292867284@sss.pgh.pa.us
обсуждение исходный текст
Ответ на libpq ASYNC with PQgetResult and PQisBusy  (Raimon Fernandez <coder@montx.com>)
Ответы Re: libpq ASYNC with PQgetResult and PQisBusy  (Raimon Fernandez <coder@montx.com>)
Re: libpq ASYNC with PQgetResult and PQisBusy  (Raimon Fernandez <coder@montx.com>)
Список pgsql-general
Raimon Fernandez <coder@montx.com> writes:
> 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.

Well, yes.  PQgetResult says wait for a result and return it.

> 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.

> 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;

> }

This code seems a bit confused.  PQisBusy returns a bool (1/0), not a
value of ExecStatusType.

            regards, tom lane

В списке pgsql-general по дате отправления:

Предыдущее
От: Merlin Moncure
Дата:
Сообщение: Re: Postgres 9.0 Hiding CONTEXT string in Logs
Следующее
От: Scott Marlowe
Дата:
Сообщение: Re: Role Membership