Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 441D19FB1DC for ; Thu, 12 Oct 2006 12:26:19 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 93462-04 for ; Thu, 12 Oct 2006 15:26:15 +0000 (UTC) X-Greylist: delayed 23:51:14.845984 by SQLgrey- Received: from apriorit.dp.ua (unknown [195.248.175.46]) by postgresql.org (Postfix) with ESMTP id 93FD19FA4C5 for ; Thu, 12 Oct 2006 12:26:14 -0300 (ADT) Received: from saint.dev.local by apriorit.com (MDaemon PRO v9.0.4) with ESMTP id md50000366078.msg for ; Thu, 12 Oct 2006 18:26:12 +0300 Date: Thu, 12 Oct 2006 18:26:00 +0300 From: Dmitriy Chumack X-Mailer: The Bat! (v3.0.1.33) Professional Reply-To: Dmitriy Chumack Organization: Apriorit X-Priority: 3 (Normal) Message-ID: <14310614201.20061012182600@apriorit.com> To: pgsql-interfaces@postgresql.org Subject: Re: [2] libpq - check PGconn* - is it valid MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Authenticated-Sender: saint@apriorit.com X-Spam-Processed: apriorit.dp.ua, Thu, 12 Oct 2006 18:26:12 +0300 (not processed: message from valid local sender) X-Return-Path: saint@apriorit.com X-MDaemon-Deliver-To: pgsql-interfaces@postgresql.org X-MDAV-Processed: apriorit.dp.ua, Thu, 12 Oct 2006 18:26:12 +0300 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=UNPARSEABLE_RELAY X-Spam-Level: X-Archive-Number: 200610/8 X-Sequence-Number: 6291 I try to use async libpq functions to test connection to db. I have such a piece of code: bool check_connection(PGconn* connection_) { int rv_ = PQsendQuery(connection_, "select 0"); PGresult* result_ = PQgetResult(connection_); if(result_) PQclear(result_); PGresult* must_be_null_ = PQgetResult(connection_); ConnStatusType status_ = PQstatus(connection_); if(status_ == CONNECTION_BAD) return false; else return true; } And I have a few problems with this code: 1) I have to call PQgetResult twice (second call returns null), otherwice from time to time PQsendQuery will return error "another command is already in progress". 2) when there is no network connection in call of both PQsendQuery and PQgetResult, then PQstatus returns CONNECTION_BAD. But when connection is ok in PQsendQuery call and is bad in PQgetResult call, then PQstatus returns CONNECTION_OK !!! 3) when there is no connections in PQsendQuery and PQgetResult, then PQgetResult hangs and it will hang (my patience end after 10 minutes) until a connection come back again. It's better then PQexec, but not that I need. I want that PQgetResult returns after a timeout. I use libpq that comes with PostgreSQL 8.1.3 on Fedora Core 5 x86_64. Does anyone have any suggestions? Thanks in advance. -- Best regards, Dmitriy Chumack mailto:saint@apriorit.com Software Developer of ApriorIT