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

From Robert Haas
Subject PQputCopyEnd doesn't adhere to its API contract
Date
Msg-id CA+Tgmobjj+0modbnmjy7ezeBFOBo9d2mAVcSPkzLx4LtZmc==g@mail.gmail.com
Whole thread Raw
Responses Re: PQputCopyEnd doesn't adhere to its API contract
List pgsql-hackers
According to the documentation for PQputCopyEnd:

> The result is 1 if the termination data was sent, zero if it was not sent because the attempt would block (this case
isonly possible if the connection is in
 
> nonblocking mode), or -1 if an error occurred. (Use PQerrorMessage to retrieve details if the return value is -1. If
thevalue is zero, wait for write-ready and try again.)
 

However, pqPutCopyEnd contains no return statement that can ever
possibly return 0.  I think the problem is approximately here:
   /* Try to flush data */   if (pqFlush(conn) < 0)       return -1;

pqFlush() returns 0 if no data is waiting to be sent, or otherwise the
return value of pqSendSome().  pqSendSome() returns -1 if an error
occurs, 0 if all data is sent, or 1 if some data was sent but the
socket is non-blocking and the caller must try again later.  It seems
to me that when pqSendSome() returns 1, pqPutCopyEnd ought to return 0
in order to meet its API contract - and then the client, presumably,
should repeatedly wait for the socket to become write-ready and then
try PQflush() until PQflush() returns non-zero.

Thoughts?

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company



pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: postgresql.auto.conf read from wrong directory
Next
From: Tom Lane
Date:
Subject: Re: popen and pclose redefinitions causing many warning in Windows build