From ced39006a2cce95cfe38ad77deba41eb90d45486 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Thu, 23 May 2019 11:12:43 +0200 Subject: [PATCH] MINOR: htx: don't rely on htx_find_blk() anymore in the function htx_truncate() 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 | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/htx.c b/src/htx.c index 60bfc049b..8ff643633 100644 --- 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);