Re: asynchronous api questions

From: "Albe Laurenz" <laurenz(dot)albe(at)wien(dot)gv(dot)at>
To: "Nulik Nol *EXTERN*" <nuliknol(at)gmail(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: asynchronous api questions
Date: 2012-01-03 11:22:52
Message-ID: D960CB61B694CF459DCFB4B0128514C20749D1C3@exadv11.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Nulik Nol wrote:
> I have 2 questions regarding the asynchronous C api (I am using vers.
8.4):
>
> 1) To make a connection in non-blocking manner the api provides PGconn
> *PQconnectStart(const char *conninfo) function. The parameters are
> passed in 'conninfo' variable which is a string so I have to use
> sprintf() to put the parameters into this string. Is there another
> function to connect asynchronously that would be similar to
> PQsetdbLogin so it would accept the host/port/user/password parameters
> directly as argument to the function? I want to avoid to use sprintf()

You can use PQconnectStartParams if you don't want to construct a
conninfo string.

> 2) Will this code produce a valid non-blocking connection ?
>
>
db_globals=PQsetdbLogin(DT_DBHOST,DT_DBPORT,NULL,NULL,"global",DT_DBUSER
,DT_DBPASS);
> if (PQstatus(db_globals) != CONNECTION_OK) {
> fprintf(stderr, "Connection to database failed: %s",
> PQerrorMessage(db_globals));
> PQfinish(db_globals);
> exit(1);
> }
> if (PQsetnonblocking(db_globals, int arg)!=1) {
> printf("can't set global connection to non blocking mode\n");
> exit(1);
> }

The resulting connection (db_globals) will not block when you send, but
the
connection procedure itself (PQsetdbLogin) will block.

Yours,
Laurenz Albe

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Vibhor Kumar 2012-01-03 12:43:49 Re: Cannot connect to 2nd cluster database remotely
Previous Message Albe Laurenz 2012-01-03 11:12:47 Re: Large Objects and and Vacuum