From: Willy Tarreau Date: Fri, 11 Dec 2020 10:04:51 +0000 (+0100) Subject: MINOR: connection: implement cs_drain_and_close() X-Git-Tag: v2.4-dev3~29 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6aee5b9a4c39b24b8afdf8d3473f0356d8e65e59;p=thirdparty%2Fhaproxy.git MINOR: connection: implement cs_drain_and_close() We had cs_close() which forces a CS_SHR_RESET mode on the read side, and due to this there are a few call places in the checks which perform a manual call to conn_sock_drain() before calling cs_close(). This is absurd by principle, and it can be counter-productive in the case of a mux where this could even cause the opposite of the desired effect by deleting pending frames on the socket before closing. Let's add cs_drain_and_close() which uses the CS_SHR_DRAIN mode to prepare this. --- diff --git a/include/haproxy/connection.h b/include/haproxy/connection.h index 776a4cb510..72ba1796af 100644 --- a/include/haproxy/connection.h +++ b/include/haproxy/connection.h @@ -267,6 +267,14 @@ static inline void cs_close(struct conn_stream *cs) cs->flags = CS_FL_NONE; } +/* completely close a conn_stream after draining possibly pending data (but do not detach it) */ +static inline void cs_drain_and_close(struct conn_stream *cs) +{ + cs_shutw(cs, CS_SHW_SILENT); + cs_shutr(cs, CS_SHR_DRAIN); + cs->flags = CS_FL_NONE; +} + /* sets CS_FL_ERROR or CS_FL_ERR_PENDING on the cs */ static inline void cs_set_error(struct conn_stream *cs) {