I use PostgreSQL 8.3 and am writing a C ++ program that uses the libpq API. I execute commands asynchronously using the PQsendQuery() function. I am trying to implement a timeout processing function. I executed it by calling PQcancel() when the timeout expired. I tested it with a query that returns 100,000 rows (it lasts about 0.5 s) with a timeout of 1 ms and found that instead of canceling the PQcancel() command, PQcancel() blocked until the server completes execution, and then will return with a successful request.
I understand that the documentation says that even with a successful request to cancel the request, the request can be fulfilled. My problem is that PQcancel() blocks my thread of execution, which is unacceptable because I use asynchronous processing (using the Boost Asio framework), so my program, which can perform other tasks besides executing the SQL query, only works on one thread.
Is it normal that PQcancel() blocks? Is there a way to make a non-blocking cancel request?
source share