Re: libpq, blocking/nonblocking mechanism

From: Terry Lee Tucker <terry(at)esc1(dot)com>
To: PostgreSQL Interfaces <pgsql-interfaces(at)postgresql(dot)org>
Subject: Re: libpq, blocking/nonblocking mechanism
Date: 2005-05-31 10:51:54
Message-ID: 200505310651.54505.terry@esc1.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

From the docs:
PQsetnonblocking

Sets the nonblocking status of the connection.

int PQsetnonblocking(PGconn *conn, int arg);

Sets the state of the connection to nonblocking if arg is 1, or blocking if
arg is 0. Returns 0 if OK, -1 if error.

In the nonblocking state, calls to PQsendQuery, PQputline, PQputnbytes, and
PQendcopy will not block but instead return an error if they need to be
called again.

Note that PQexec does not honor nonblocking mode; if it is called, it will act
in blocking fashion anyway.

A call to PQsetnonblocking only affects PQsendQuery, etc. These commands will
work without calling PQsetnonblocking, but they will block. Our application
uses a combination of PQexec and PQsendQuery.

I'm looking at the documentation in:
file:/usr/share/doc/postgresql-7.4.6/html/libpq-async.html
on my machine.

On Saturday 28 May 2005 04:34 pm, Volkan YAZICI saith:
> Hi,
>
> While I'm trying to figure out the point of PQsetnonblocking() call,
> confused so much on blocking/nonblocking mechanism.
>
> Sync. Connect » Async. Query
> Async. Connect » Sync. Query
>
> Both of above flows work without any PQsetnonblocking() call.
> Therefore sync/async connection and sync/async query execution are not
> dependent to each other. (Right?) If so, what's the point of
> PQsetnonblocking() function? When do we require it and when should we
> use it?
>
> As I saw from src/interfaces/libpq/fe-exec.c, PQsetnonblocking() only
> assigns True or False to conn->nonblocking variable. When I searched
> for "->nonblocking" under libpq directory, I found that it's used
> while creating an empty PGconn and while closing PGconn. This didn't
> help me too.
>
> I'd be so appreciated for a comprehensive "specialized for dummies" answer.
> Regards.
>
> P.S. Documentation pointers will be accepted with pleasure too.
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq

In response to

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Volkan YAZICI 2005-06-01 18:18:18 Re: libpq, blocking/nonblocking mechanism
Previous Message sql 2005-05-30 09:28:29 Re: MacOS Interface ?