]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: protocol: improve the proto->drain() API
authorWilly Tarreau <w@1wt.eu>
Mon, 20 Jan 2014 10:26:12 +0000 (11:26 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 20 Jan 2014 21:27:16 +0000 (22:27 +0100)
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

src/checks.c
src/proto_tcp.c
src/stream_interface.c

index 52cf47c435f79d0af5131a3c3b80db2fa6ff3da5..4682b2cd9e09b44b2ee256b73388ab8f17958c2e 100644 (file)
@@ -1446,7 +1446,7 @@ static int wake_srv_chk(struct connection *conn)
                 * sure want to abort the hard way.
                 */
                if (conn_ctrl_ready(conn) && !(conn->flags & CO_FL_SOCK_RD_SH)) {
-                       if (!(conn->flags & CO_FL_WAIT_RD) && conn->ctrl->drain && conn->ctrl->drain(conn->t.sock.fd))
+                       if (!(conn->flags & CO_FL_WAIT_RD) && conn->ctrl->drain && conn->ctrl->drain(conn->t.sock.fd) > 0)
                                fdtab[conn->t.sock.fd].linger_risk = 0;
                }
                conn_force_close(conn);
@@ -1665,7 +1665,7 @@ static struct task *process_chk(struct task *t)
                         * server state to be suddenly changed.
                         */
                        if (conn_ctrl_ready(conn) && !(conn->flags & CO_FL_SOCK_RD_SH)) {
-                               if (!(conn->flags & CO_FL_WAIT_RD) && conn->ctrl->drain && conn->ctrl->drain(conn->t.sock.fd))
+                               if (!(conn->flags & CO_FL_WAIT_RD) && conn->ctrl->drain && conn->ctrl->drain(conn->t.sock.fd) > 0)
                                        fdtab[conn->t.sock.fd].linger_risk = 0;
                        }
                        conn_force_close(conn);
index c1b0d7bdd6ec8ea4cb00bd0b1fb519a6cb1569ae..c02409d7205b69c418ad8eafe4557ef621a2586d 100644 (file)
@@ -525,9 +525,9 @@ int tcp_get_dst(int fd, struct sockaddr *sa, socklen_t salen, int dir)
 }
 
 /* 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 @@ int tcp_drain(int fd)
 
                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. */
index f38ddc13cf4f281a1c63459bf1fb390c8b0cb800..b9cb79949bfea27b90fe6b934dbb03323f57e489 100644 (file)
@@ -499,7 +499,7 @@ static void si_idle_conn_null_cb(struct connection *conn)
                return;
 
        if ((fdtab[conn->t.sock.fd].ev & (FD_POLL_ERR|FD_POLL_HUP)) ||
-           (conn->ctrl->drain && conn->ctrl->drain(conn->t.sock.fd)))
+           (conn->ctrl->drain && conn->ctrl->drain(conn->t.sock.fd) > 0))
                conn->flags |= CO_FL_SOCK_RD_SH;
 
        /* disable draining if we were called and have no drain function */