]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: htx: don't rely on htx_find_blk() anymore in the function htx_truncate()
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 23 May 2019 09:12:43 +0000 (11:12 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 28 May 2019 05:42:33 +0000 (07:42 +0200)
the function htx_find_blk() is used by only one function, htx_truncate(). So
because this function does nothing very smart, we don't use it anymore. It will
be removed by another commit.

src/htx.c

index 60bfc049b2615c790854a0f796199c96d879634b..8ff643633618c71ccb5f041dede2190c78b98fbe 100644 (file)
--- a/src/htx.c
+++ b/src/htx.c
@@ -284,15 +284,20 @@ 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 *blk;
-       struct htx_ret htxret;
 
-       htxret = htx_find_blk(htx, offset);
-       blk = htxret.blk;
-       if (blk && htxret.ret) {
+       for (blk = htx_get_head_blk(htx); blk && offset; blk = htx_get_next_blk(htx, blk)) {
                uint32_t sz = htx_get_blksz(blk);
+               enum htx_blk_type type = htx_get_blk_type(blk);
 
-               htx_set_blk_value_len(blk, sz - htxret.ret);
-               blk = htx_get_next_blk(htx, blk);
+               if (offset >= sz) {
+                       offset -= sz;
+                       continue;
+               }
+               if (type == HTX_BLK_DATA || type == HTX_BLK_TLR) {
+                       htx_set_blk_value_len(blk, offset);
+                       htx->data -= (sz - offset);
+               }
+               offset = 0;
        }
        while (blk)
                blk = htx_remove_blk(htx, blk);