]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: channel/htx: Add the HTX version of channel_truncate/erase
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 7 Jan 2019 13:55:10 +0000 (14:55 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 8 Jan 2019 11:06:55 +0000 (12:06 +0100)
The function channel_htx_truncate() can now be used on HTX buffer to truncate
all incoming data, keeping outgoing one intact. This function relies on the
function channel_htx_erase() and htx_truncate().

This patch may be backported to 1.9. If so, the patch "MINOR: channel/htx: Add
the HTX version of channel_truncate()" must also be backported.

include/proto/channel.h

index 0cd842a189a814e4d759bee128777474afd80c4f..d16b0e7306862e52a9396a07c5feaa1e76120209 100644 (file)
@@ -548,6 +548,12 @@ static inline void channel_erase(struct channel *chn)
        b_reset(&chn->buf);
 }
 
+static inline void channel_htx_erase(struct channel *chn, struct htx *htx)
+{
+       htx_reset(htx);
+       channel_erase(chn);
+}
+
 /* marks the channel as "shutdown" ASAP for reads */
 static inline void channel_shutr_now(struct channel *chn)
 {
@@ -877,6 +883,17 @@ static inline void channel_truncate(struct channel *chn)
        chn->buf.data = co_data(chn);
 }
 
+static inline void channel_htx_truncate(struct channel *chn, struct htx *htx)
+{
+       if (!co_data(chn))
+               return channel_htx_erase(chn, htx);
+
+       chn->to_forward = 0;
+       if (htx->data == co_data(chn))
+               return;
+       htx_truncate(htx, co_data(chn));
+}
+
 /* This function realigns a possibly wrapping channel buffer so that the input
  * part is contiguous and starts at the beginning of the buffer and the output
  * part ends at the end of the buffer. This provides the best conditions since