Re: PQputCopyEnd doesn't adhere to its API contract - Mailing list pgsql-hackers

From Tom Lane
Subject Re: PQputCopyEnd doesn't adhere to its API contract
Date
Msg-id 30079.1399584096@sss.pgh.pa.us
Whole thread Raw
In response to Re: PQputCopyEnd doesn't adhere to its API contract  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: PQputCopyEnd doesn't adhere to its API contract
Re: PQputCopyEnd doesn't adhere to its API contract
List pgsql-hackers
Robert Haas <robertmhaas@gmail.com> writes:
> On Thu, May 8, 2014 at 1:51 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Robert Haas <robertmhaas@gmail.com> writes:
>>> OK.  It still seems to me that there's a doc fix needed here, if
>>> nothing else.  The documentation for PQputCopyEnd() clearly implies
>>> that if you get a return value of 1, the message is sent, and that's
>>> just not true.

>> That's fair.

> Something like the attached?

> I don't really know what to say about 0, since it's never actually
> returned, so I left that out.  But I'm up for suggestions.

I think you should leave the existing verbiage about zero alone.
If we take it out, we're painting ourselves into a corner about
ever fixing the buffer-is-too-full failure case.

Perhaps the text should be like this:

The result is 1 if the termination message was sent; or in nonblocking
mode, this may only indicate that the termination message was successfully
queued.  (In nonblocking mode, to be certain that the data has been sent,
you should next wait for write-ready and call <function>PQflush</>,
repeating until it returns zero.)  Zero indicates that the function could
not queue the termination message because of full buffers; this will only
happen in nonblocking mode.  (In this case, wait for write-ready and try
the PQputCopyEnd call again.)  If a hard error occurs, -1 is returned; you
can use <function>PQerrorMessage</function> to retrieve details.

If it bothers you to document behavior that's not actually there yet,
maybe you should go fix the bug ;-).  I had thought this would require
a lot of refactoring, but it might work to just check if there's enough
buffer space for the message and return zero immediately if not.
        regards, tom lane



pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: Sending out a request for more buildfarm animals?
Next
From: Simon Riggs
Date:
Subject: Re: [v9.5] Custom Plan API