Skip to content

Commit fbdb0a9

Browse files
committed
MINOR: htx: Add function to truncate all blocks after a specific block
htx_truncated_blk() function does the same than htx_trunctate(), except data are truncated relatively to a block in the message instead of an offset.
1 parent 3250ec6 commit fbdb0a9

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

include/haproxy/htx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ struct htx_blk *htx_add_blk(struct htx *htx, enum htx_blk_type type, uint32_t bl
3737
struct htx_blk *htx_remove_blk(struct htx *htx, struct htx_blk *blk);
3838
struct htx_ret htx_find_offset(struct htx *htx, uint32_t offset);
3939
void htx_truncate(struct htx *htx, uint32_t offset);
40+
void htx_truncate_blk(struct htx *htx, struct htx_blk *blk);
4041
struct htx_ret htx_drain(struct htx *htx, uint32_t max);
4142

4243
struct htx_blk *htx_replace_blk_value(struct htx *htx, struct htx_blk *blk,

src/htx.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,18 @@ void htx_truncate(struct htx *htx, uint32_t offset)
469469
blk = htx_remove_blk(htx, blk);
470470
}
471471

472+
/* Removes all blocks after <blk>, excluding it. if <blk> is NULL, all blocks
473+
* are removed.
474+
*/
475+
void htx_truncate_blk(struct htx *htx, struct htx_blk *blk)
476+
{
477+
if (!blk) {
478+
htx_drain(htx, htx->data);
479+
return;
480+
}
481+
for (blk = htx_get_next_blk(htx, blk); blk; blk = htx_remove_blk(htx, blk));
482+
}
483+
472484
/* Drains <count> bytes from the HTX message <htx>. If the last block is a DATA
473485
* block, it will be cut if necessary. Others blocks will be removed at once if
474486
* <count> is large enough. The function returns an htx_ret with the first block

0 commit comments

Comments
 (0)