Re: PQisBusy() always busy - Mailing list pgsql-novice
From | Merlin Moncure |
---|---|
Subject | Re: PQisBusy() always busy |
Date | |
Msg-id | CAHyXU0wEAfHmZHiL7KS+BjXQ6u8vsNf3tXQMYfyfDqsx11uTCQ@mail.gmail.com Whole thread Raw |
In response to | PQisBusy() always busy (bradg <bg4all@me.com>) |
Responses |
Re: PQisBusy() always busy
|
List | pgsql-novice |
On Mon, Sep 12, 2011 at 6:16 AM, bradg <bg4all@me.com> wrote: > It seems like PQisBusy() == 1 indefinitely after calling the asynchronous > function PQsendQueryParams(). > > I am using a method to check for the availability of asynchronous results > straight out of the latest PostgreSQL book by Korry and Susan Douglas. It > uses select() and then FD_ISSET on the connection socket, then calls both > PQconsumeInput() and PQisBusy(). > > For some reason, the value for PQisBusy() is always 1, no matter how long I > let the program run. > > I'm just wondering if anyone can point me in the right direction. For what > it's worth. I'm programming in OS X 10.7 with Xcode 4.1 using the PostgreSQL > files from the EnterpriseDB one-click installer. > > Here's the function: > > bool is_result_ready( PGconn * connection ) > { > int my_socket; > struct timeval timer; > fd_set read_mask; > > if( PQisBusy( connection ) == FALSE ) > return( TRUE ); > > my_socket = PQsocket( connection ); > > timer.tv_sec = (time_t)1; > timer.tv_usec = 0; > > FD_ZERO( &read_mask ); > FD_SET( my_socket, &read_mask ); > > if( select( my_socket + 1, &read_mask, NULL, NULL, &timer ) == 0 ) > { > return( FALSE ); > } > else if( FD_ISSET( my_socket, &read_mask )) > { > PQconsumeInput( connection ); > > if( PQisBusy( connection )) <------ THIS PQisBusy() ALWAYS > RETURNS 1 > return( FALSE ); > else > return( TRUE ); > } > else > { > return( FALSE ); > } > } > > > Thanks in advance for any insight. You are not checking the return of PQconsumeInput -- if there is a problem with the connection, you won't catch the change to the internal asyncStatus flag because it only gets changed from data returned over the socket. Try changing your code to watch for PQconsumeInput return value, and displaying/handling the connection error if there is a problem. per docs: "PQconsumeInput normally returns 1 indicating "no error", but returns 0 if there was some kind of trouble (in which case PQerrorMessage can be consulted). Note that the result does not say whether any input data was actually collected. After calling PQconsumeInput, the application can check PQisBusy and/or PQnotifies to see if their state has changed." merlin
pgsql-novice by date: