Re: pqlib in c++: PQconnectStart PQconnectPoll

From: "madhtr" <madhtr(at)schif(dot)org>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: pqlib in c++: PQconnectStart PQconnectPoll
Date: 2007-02-14 21:11:38
Message-ID: 001401c7507c$b7d62520$7b55503f@useronewin2klt
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

ok thanx:)

... here's the source ... can u tell me whats wrong? (the purpose of this
function is to allow for thread safety on the connection, and allow for
cancellation if the connection takes too long)

BTW ...

- coninfo is "host=localhost port=5432 dbname=testdb user=localuser
password=localpassword"
- I am using VC++ and compiling a windows execuatble ...

PGconn* PQconnectStartCS(const char* coninfo,LPCRITICAL_SECTION lpcs,bool*
lpcancel,int* lppge){
int& pge = *lppge;
bool& cancel = *lpcancel;
bool keepon = true;
PGconn* pr = 0;
pge = 0;
EnterCriticalSection(lpcs);
pr = PQconnectStart(coninfo);

while (!killthread(&cancel) && keepon){
switch(pge = PQconnectPoll(pr)){
case PGRES_POLLING_FAILED:
keepon = false;
break;
case PGRES_POLLING_OK:
pge = 0;
keepon = false;
break;
default:
break;
};
if (keepon)
Sleep(1);
};

LeaveCriticalSection(lpcs);
if (!pge && pr){
switch(pge = PQstatus(pr)){
case CONNECTION_OK:
pge = 0;
break;
};
};
return pr;
};

----- Original Message -----
From: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "madhtr" <madhtr(at)schif(dot)org>
Cc: <pgsql-general(at)postgresql(dot)org>
Sent: Tuesday, August 14, 2007 14:36
Subject: Re: [GENERAL] pqlib in c++: PQconnectStart PQconnectPoll

> "madhtr" <madhtr(at)schif(dot)org> writes:
>> when i intentioally try to connect asynchronously to a database that does
>> not exist, i get
>
>> "server closed the connection unexpectedly"
>
> There's something wrong with your code then.
>
> regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings
----- Original Message -----
From: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "madhtr" <madhtr(at)schif(dot)org>
Cc: <pgsql-general(at)postgresql(dot)org>
Sent: Tuesday, August 14, 2007 14:36
Subject: Re: [GENERAL] pqlib in c++: PQconnectStart PQconnectPoll

> "madhtr" <madhtr(at)schif(dot)org> writes:
>> when i intentioally try to connect asynchronously to a database that does
>> not exist, i get
>
>> "server closed the connection unexpectedly"
>
> There's something wrong with your code then.
>
> regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Paul Lambert 2007-02-14 21:13:20 Re: How to search, how to post?
Previous Message Ron Johnson 2007-02-14 21:09:49 Re: Recover anything from dropped database?