Re: Fix for non-blocking connections in libpq - Mailing list pgsql-patches

From Bruce Momjian
Subject Re: Fix for non-blocking connections in libpq
Date
Msg-id 200202230224.g1N2OLE04449@candle.pha.pa.us
Whole thread Raw
In response to Fix for non-blocking connections in libpq  (Bernhard Herzog <bh@intevation.de>)
List pgsql-patches
Your patch has been added to the PostgreSQL unapplied patches list at:

    http://candle.pha.pa.us/cgi-bin/pgpatches

I will try to apply it within the next 48 hours.

---------------------------------------------------------------------------


Bernhard Herzog wrote:
>
> Here's a patch against 7.1.3 that fixes a problem with sending larger
> queries over non-blocking connections with libpq. "Larger" here
> basically means that it doesn't fit into the output buffer.
>
> The basic strategy is to fix pqFlush and pqPutBytes.
>
> The problem with pqFlush as it stands now is that it returns EOF when an
> error occurs or when not all data could be sent. The latter case is
> clearly not an error for a non-blocking connection but the caller can't
> distringuish it from an error very well.
>
> The first part of the fix is therefore to fix pqFlush. This is done by
> to renaming it to pqSendSome which only differs from pqFlush in its
> return values to allow the caller to make the above distinction and a
> new pqFlush which is implemented in terms of pqSendSome and behaves
> exactly like the old pqFlush.
>
> The second part of the fix modifies pqPutBytes to use pqSendSome instead
> of pqFlush and to either send all the data or if not all data can be
> sent on a non-blocking connection to at least put all data into the
> output buffer, enlarging it if necessary. The callers of pqPutBytes
> don't have to be changed because from their point of view pqPutBytes
> behaves like before. It either succeeds in queueing all output data or
> fails with an error.
>
> I've also added a new API function PQsendSome which analogously to
> PQflush just calls pqSendSome. Programs using non-blocking queries
> should use this new function. The main difference is that this function
> will have to be called repeatedly (calling select() properly in between)
> until all data has been written.
>
> AFAICT, the code in CVS HEAD hasn't changed with respect to non-blocking
> queries and this fix should work there, too, but I haven't tested that
> yet.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

pgsql-patches by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: enable debugging in jdbc
Next
From: Bruce Momjian
Date:
Subject: Re: [PATCH] GiST code cleanup