]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: dynbuf: Add helper functions to alloc large and small buffers
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 10 Mar 2026 07:09:12 +0000 (08:09 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 23 Mar 2026 13:02:42 +0000 (14:02 +0100)
b_alloc_small() and b_alloc_large() can now be used to alloc small or larger
buffers. For now, unlike default buffers, buffer_wait lists are not used.

include/haproxy/dynbuf.h

index d487e1068ab44e34fe4e3783513d4f90a42a7aeb..c8d7a5bcd88ac6fa9cbd6664c27512e158e21e7e 100644 (file)
@@ -200,6 +200,35 @@ static inline char *__b_get_emergency_buf(void)
                        __b_free((_buf));       \
        } while (0)
 
+
+static inline struct buffer *b_alloc_small(struct buffer *buf)
+{
+       char *area = NULL;
+
+       if (!buf->size) {
+               area = pool_alloc(pool_head_small_buffer);
+               if (!area)
+                       return NULL;
+               buf->area = area;
+               buf->size = global.tune.bufsize_small;
+       }
+       return buf;
+}
+
+static inline struct buffer *b_alloc_large(struct buffer *buf)
+{
+       char *area = NULL;
+
+       if (!buf->size) {
+               area = pool_alloc(pool_head_large_buffer);
+               if (!area)
+                       return NULL;
+               buf->area = area;
+               buf->size = global.tune.bufsize_large;
+       }
+       return buf;
+}
+
 /* Offer one or multiple buffer currently belonging to target <from> to whoever
  * needs one. Any pointer is valid for <from>, including NULL. Its purpose is
  * to avoid passing a buffer to oneself in case of failed allocations (e.g.