From: Amaury Denoyelle Date: Thu, 16 Oct 2025 14:41:24 +0000 (+0200) Subject: MINOR: ncbuf2: implement init / is_empty X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d13073a9309ef8d18947b8db90de91eb003dc11b;p=thirdparty%2Fhaproxy.git MINOR: ncbuf2: implement init / is_empty --- diff --git a/include/haproxy/ncbuf2.h b/include/haproxy/ncbuf2.h index 7220b4e78..40b2586c6 100644 --- a/include/haproxy/ncbuf2.h +++ b/include/haproxy/ncbuf2.h @@ -9,6 +9,7 @@ static inline int ncb2_is_null(const struct ncbuf2 *buf) return buf->size == 0; } +void ncb2_init(struct ncbuf2 *buf, ncb2_sz_t head); struct ncbuf2 ncb2_make(char *area, ncb2_sz_t size, ncb2_sz_t head); static inline char *ncb2_orig(const struct ncbuf2 *buf) @@ -34,6 +35,8 @@ static inline ncb2_sz_t ncb2_size(const struct ncbuf2 *buf) return buf->size; } +int ncb2_is_empty(const struct ncbuf2 *buf); + ncb2_sz_t ncb2_data(const struct ncbuf2 *buf, ncb2_sz_t offset); enum ncb_ret ncb2_add(struct ncbuf2 *buf, ncb2_sz_t off, diff --git a/src/ncbuf2.c b/src/ncbuf2.c index ba1a6ab61..f396a6372 100644 --- a/src/ncbuf2.c +++ b/src/ncbuf2.c @@ -132,6 +132,15 @@ static void bit_unset(unsigned char *value, char i) /* ******** public API ******** */ +void ncb2_init(struct ncbuf2 *buf, ncb2_sz_t head) +{ + BUG_ON_HOT(ncb2_is_null(buf)); + + BUG_ON_HOT(head >= buf->size); + buf->head = head; + memset(buf->bitmap, 0, buf->bitmap_sz); +} + struct ncbuf2 ncb2_make(char *area, ncb2_sz_t size, ncb2_sz_t head) { struct ncbuf2 buf; @@ -158,8 +167,17 @@ ncb2_sz_t ncb2_total_data(const struct ncbuf2 *buf) int ncb2_is_empty(const struct ncbuf2 *buf) { - /* TODO */ - return 0; + size_t i = 0; + + if (ncb2_is_null(buf)) + return 1; + + for (i = 0; i < buf->bitmap_sz; ++i) { + if (buf->bitmap[i]) + return 0; + } + + return 1; } int ncb2_is_full(const struct ncbuf2 *buf)