PQisBusy returns true but no more data is received.

Поиск
Список
Период
Сортировка
От Pelle Johansson
Тема PQisBusy returns true but no more data is received.
Дата
Msg-id 83326227-45CB-42B6-BCD6-2646E037FCAA@morth.org
обсуждение исходный текст
Ответы Re: PQisBusy returns true but no more data is received.  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
Hello list,

I'm new here, but didn't see the problem in the archives.

Basically, I have an epoll loop that executes the following code when
I receive data from postgresql (greatly simplified).

int read_sql (PGconn *conn)
{
   PGnotify *notice;
   PGresult *res;

   if (!PQconsumeInput (conn))
     return -1;

   while (1)
   {
     while ((notice = PQnotifies (conn)))
     {
       handle_notice (notice);
       PQmemfree (notice);
     }

     if (PQisBusy (conn))
       return 0;

     res = PQgetResult (conn);
     if (!res)
       break;

     while ((notice = PQnotifies (conn)))
     {
       handle_notice (notice);
       PQmemfree (notice);
     }

     handle_result (res);
     PQclear (res);
   }

   handle_query_done (conn);
}

(I've not tried to compile this sample code.)
The SQL query in question is a BEGIN followed by a SELECT (sent in
the same PQsendQuery()).

The problem is that after two iterations in the loop PQisBusy()
returns true, making me exit to the event loop, but no more data is
received, so the function will not be called again. If I disable the
call to PQisBusy() everything works as expected (PQgetResult() will
return NULL on the third iteration). If I move the call to PQisBusy()
outside the loop, everything also works good.

Is it safe to move the call to PQisBusy() outside the loop, or is it
possible that PQgetResult() will block on a long SELECT in that case?
(that would be very bad for me). Or have I misunderstood something
about these functions?
--
Pelle Johansson


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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: How many postmasters should be running?
Следующее
От: Volkan YAZICI
Дата:
Сообщение: Re: Breaking Path/Polygon Data into Pieces