X-Original-To: pgsql-interfaces@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 5E9594753A1 for ; Mon, 10 Feb 2003 22:53:05 -0500 (EST) Received: from news.hub.org (news.hub.org [64.49.215.80]) by postgresql.org (Postfix) with ESMTP id E879A474E53 for ; Mon, 10 Feb 2003 22:53:04 -0500 (EST) Received: by news.hub.org (Postfix, from userid 8) id A742943A756; Mon, 10 Feb 2003 22:53:04 -0500 (EST) From: "Frankie Lam" X-Newsgroups: comp.databases.postgresql.interfaces Subject: Any timeout feature(in libPQ) suitable for my case? Date: Tue, 11 Feb 2003 11:53:39 +0800 Organization: Hub.Org Networking Services (http://www.hub.org) Lines: 85 Message-ID: X-Complaints-To: usenet@news.hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 To: pgsql-interfaces@postgresql.org X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200302/25 X-Sequence-Number: 3646 I'm sorry if I go the wrong place. I wonder if there is a timeout feature for limiting the lifetime of a connection in libPQ. Please have a look at the simple demo program of my problem below. #include #include void printTuples(PGresult *result) { int r, n; int nrows = PQntuples(result); int nfields = PQnfields(result); printf("number of rows returned = %d\n", nrows); printf("number of fields returned = %d\n", nfields); for(r = 0; r < nrows; r++) { for(n = 0; n < nfields; n++) printf(" %s = %s(%d),", PQfname(result, n), PQgetvalue(result, r, n), PQgetlength(result, r, n)); printf("\n"); } } void doSQL(PGconn *conn, char *command) { PGresult *result; printf("%s\n", command); result = PQexec(conn, command); printf("status is %s\n", PQresStatus(PQresultStatus(result))); printf("#rows affected %s\n", PQcmdTuples(result)); printf("result message: %s\n", PQresultErrorMessage(result)); switch(PQresultStatus(result)) { case PGRES_TUPLES_OK: printTuples(result); break; } PQclear(result); } int main() { PGresult *result; PGconn *conn; int a=-1; conn = PQconnectdb("hostaddr=192.168.1.50 dbname=twins connect_timeout=1"); if(PQstatus(conn) == CONNECTION_OK && PQsetnonblocking(conn,1) == 0) { printf("connection made\n"); sleep(10); //<<<== sleep for 10 seconds so I have enough time to unplug the cable. //GO AND UNPLUG THE NETWORK CABLE to the 192.168.1.50 before it wakes up. //After unplugging the cable, it gets stuck here unless I plug the cable back again, //connect_timeout is no use :-( while(result = PQgetResult(conn)) { printTuples(result); PQclear(result); } } else printf("connection failed\n"); PQfinish(conn); return EXIT_SUCCESS; } Any info given is very much appreciated Frankie