]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: connection: make conn_drain() perform more controls
authorWilly Tarreau <w@1wt.eu>
Thu, 12 Mar 2015 23:32:20 +0000 (00:32 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 12 Mar 2015 23:32:20 +0000 (00:32 +0100)
Currently si_idle_conn_null_cb() has to perform some low-level checks
over the file descriptor and the connection configuration that should
only belong to conn_drain(). Let's move these controls there. The
function now automatically checks for errors and hangups on the file
descriptor for example, and disables recv polling if there's no drain
function at the control layer.

include/proto/connection.h
src/stream_interface.c

index 27922f3dbf86c04b7478e94d20034dec02065eec..f542cb2dbea8ecc635f483348150635f1d2f7748 100644 (file)
@@ -552,17 +552,25 @@ static inline int conn_drain(struct connection *conn)
        if (!conn_ctrl_ready(conn))
                return 1;
 
-       if (conn->flags & CO_FL_SOCK_RD_SH)
+       if (conn->flags & (CO_FL_ERROR | CO_FL_SOCK_RD_SH))
                return 1;
 
-       if (!fd_recv_ready(conn->t.sock.fd))
-               return 0;
-
-       if (!conn->ctrl->drain)
-               return 0;
-
-       if (conn->ctrl->drain(conn->t.sock.fd) <= 0)
-               return 0;
+       if (fdtab[conn->t.sock.fd].ev & (FD_POLL_ERR|FD_POLL_HUP)) {
+               fdtab[conn->t.sock.fd].linger_risk = 0;
+       }
+       else {
+               if (!fd_recv_ready(conn->t.sock.fd))
+                       return 0;
+
+               /* disable draining if we were called and have no drain function */
+               if (!conn->ctrl->drain) {
+                       __conn_data_stop_recv(conn);
+                       return 0;
+               }
+
+               if (conn->ctrl->drain(conn->t.sock.fd) <= 0)
+                       return 0;
+       }
 
        conn->flags |= CO_FL_SOCK_RD_SH;
        return 1;
index 3fc1e569355f94e344cf8b8dbab511a78a1dad56..8450117c236ca3483fa4c994d541fd7d912f21dd 100644 (file)
@@ -497,20 +497,7 @@ int conn_si_send_proxy(struct connection *conn, unsigned int flag)
  */
 static void si_idle_conn_null_cb(struct connection *conn)
 {
-       if (conn->flags & (CO_FL_ERROR | CO_FL_SOCK_RD_SH))
-               return;
-
-       if (fdtab[conn->t.sock.fd].ev & (FD_POLL_ERR|FD_POLL_HUP)) {
-               fdtab[conn->t.sock.fd].linger_risk = 0;
-               conn->flags |= CO_FL_SOCK_RD_SH;
-       }
-       else {
-               conn_drain(conn);
-       }
-
-       /* disable draining if we were called and have no drain function */
-       if (!conn->ctrl->drain)
-               __conn_data_stop_recv(conn);
+       conn_drain(conn);
 }
 
 /* Callback to be used by connection I/O handlers when some activity is detected