]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: htx: Add a function to truncate all blocks after a specific offset
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 7 Jan 2019 13:53:27 +0000 (14:53 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 8 Jan 2019 11:06:55 +0000 (12:06 +0100)
This function will be used to truncate all incoming data in a channel, keeping
outgoing ones.

This may be backported to 1.9.

include/common/htx.h
src/htx.c

index 56a6c9b969e8f1c10e9236bee94c2cb43f68fde8..94df4bbd484b91e8091895d4ba35ab7769a778b5 100644 (file)
@@ -170,6 +170,7 @@ extern struct htx htx_empty;
 struct htx_blk *htx_defrag(struct htx *htx, struct htx_blk *blk);
 struct htx_blk *htx_add_blk(struct htx *htx, enum htx_blk_type type, uint32_t blksz);
 struct htx_blk *htx_remove_blk(struct htx *htx, struct htx_blk *blk);
+void htx_truncate(struct htx *htx, uint32_t offset);
 
 struct htx_blk *htx_replace_blk_value(struct htx *htx, struct htx_blk *blk,
                                      const struct ist old, const struct ist new);
index af94643440902deb2dcb7e59e53c26c5b5c964a4..3e7e4df38435267dcb96d00104eb5b3fd921d017 100644 (file)
--- a/src/htx.c
+++ b/src/htx.c
@@ -287,6 +287,26 @@ struct htx_blk *htx_remove_blk(struct htx *htx, struct htx_blk *blk)
        return blk;
 }
 
+/* Truncate all blocks after the one containing the offset <offset>. This last
+ * one is truncated too.
+ */
+void htx_truncate(struct htx *htx, uint32_t offset)
+{
+       struct htx_blk *blk;
+       struct htx_ret htxret;
+
+       htxret = htx_find_blk(htx, offset);
+       blk = htxret.blk;
+       if (blk && htxret.ret) {
+               uint32_t sz = htx_get_blksz(blk);
+
+               htx_set_blk_value_len(blk, sz - htxret.ret);
+               blk = htx_get_next_blk(htx, blk);
+       }
+       while (blk)
+               blk = htx_remove_blk(htx, blk);
+}
+
 /* Tries to append data to the last inserted block, if the type matches and if
  * there is enough non-wrapping space. Only DATA and TRAILERS content can be
  * appended. If the append fails, a new block is inserted. If an error occurred,