MINOR: protocol: improve the proto->drain() API
It was not possible to know if the drain() function had hit an
EAGAIN, so now we change the API of this function to return :
< 0 if EAGAIN was met
= 0 if some data remain
> 0 if a shutdown was received
diff --git a/src/proto_tcp.c b/src/proto_tcp.c
index c1b0d7b..c02409d 100644
--- a/src/proto_tcp.c
+++ b/src/proto_tcp.c
@@ -525,9 +525,9 @@
}
/* Tries to drain any pending incoming data from the socket to reach the
- * receive shutdown. Returns non-zero if the shutdown was found, otherwise
- * zero. This is useful to decide whether we can close a connection cleanly
- * are we must kill it hard.
+ * receive shutdown. Returns positive if the shutdown was found, negative
+ * if EAGAIN was hit, otherwise zero. This is useful to decide whether we
+ * can close a connection cleanly are we must kill it hard.
*/
int tcp_drain(int fd)
{
@@ -546,7 +546,7 @@
if (len < 0) {
if (errno == EAGAIN) /* connection not closed yet */
- return 0;
+ return -1;
if (errno == EINTR) /* oops, try again */
continue;
/* other errors indicate a dead connection, fine. */