]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: connection: add a new CO_FL_WANT_DRAIN flag to force drain on close
authorWilly Tarreau <w@1wt.eu>
Thu, 21 Oct 2021 19:31:42 +0000 (21:31 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 21 Oct 2021 19:48:23 +0000 (21:48 +0200)
Sometimes we'd like to do our best to drain pending data before closing
in order to save the peer from risking to receive an RST on close.

This adds a new connection flag CO_FL_WANT_DRAIN that is used to
trigger a call to conn_ctrl_drain() from conn_ctrl_close(), and the
sock_drain() function ignores fd_recv_ready() if this flag is set,
in order to catch latest data. It's not used for now.

include/haproxy/connection-t.h
include/haproxy/connection.h
src/sock.c

index 0ba8555ff3d9e4bdf02290f04aaa364111d36824..68ab91ae8ae5df60cab7540fedb879fb2e7b3864 100644 (file)
@@ -131,7 +131,7 @@ enum {
        CO_FL_CTRL_READY    = 0x00000100, /* FD was registered, fd_delete() needed */
        CO_FL_XPRT_READY    = 0x00000200, /* xprt_start() done, xprt can be used */
 
-       /* unused : 0x00000400 */
+       CO_FL_WANT_DRAIN    = 0x00000400, /* try to drain pending data when closing */
 
        /* This flag is used by data layers to indicate they had to stop
         * receiving data because a buffer was full. The connection handler
index 17dad4bdaf15f819e2b4a4bf5c55fb17059907f2..7c970e2bdd9c7659d24b655cfce7d0a4c215b5f2 100644 (file)
@@ -174,6 +174,8 @@ static inline void conn_ctrl_init(struct connection *conn)
 static inline void conn_ctrl_close(struct connection *conn)
 {
        if (!conn->xprt && (conn->flags & CO_FL_CTRL_READY)) {
+               if ((conn->flags & (CO_FL_WANT_DRAIN | CO_FL_SOCK_RD_SH)) == CO_FL_WANT_DRAIN)
+                       conn_ctrl_drain(conn);
                conn->flags &= ~CO_FL_CTRL_READY;
                if (conn->ctrl->ctrl_close)
                        conn->ctrl->ctrl_close(conn);
index d05cf7e6917c509ed76c40313cb384125e91800c..e546d8f4a1365d481a5bd29264317c2d111ca600 100644 (file)
@@ -836,7 +836,7 @@ int sock_drain(struct connection *conn)
        if (fdtab[fd].state & (FD_POLL_ERR|FD_POLL_HUP))
                goto shut;
 
-       if (!fd_recv_ready(fd))
+       if (!(conn->flags & CO_FL_WANT_DRAIN) && !fd_recv_ready(fd))
                return 0;
 
        /* no drain function defined, use the generic one */