]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: buffer: provide a new buffer_full() function
authorWilly Tarreau <wtarreau@exceliance.fr>
Mon, 27 Aug 2012 17:51:36 +0000 (19:51 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 3 Sep 2012 18:47:33 +0000 (20:47 +0200)
This one only focuses on the input part of the buffer and is dedicated
to analysers.

include/common/buffer.h

index b1b7c4607dcee935bd5d2c020fdb9eb31345f3b8..cf40f096bfab7c3f8e09ca7c8ec3c0150773972b 100644 (file)
@@ -156,6 +156,20 @@ static inline int buffer_empty(const struct buffer *buf)
        return !buffer_not_empty(buf);
 }
 
+/* Returns non-zero if the buffer's INPUT is considered full, which means that
+ * it holds at least as much INPUT data as (size - reserve). This also means
+ * that data that are scheduled for output are considered as potential free
+ * space, and that the reserved space is always considered as not usable. This
+ * information alone cannot be used as a general purpose free space indicator.
+ * However it accurately indicates that too many data were fed in the buffer
+ * for an analyzer for instance. See the channel_full() function for a more
+ * generic function taking everything into account.
+ */
+static inline int buffer_full(const struct buffer *b, unsigned int reserve)
+{
+       return (b->i + reserve >= b->size);
+}
+
 /* Normalizes a pointer after a subtract */
 static inline char *buffer_wrap_sub(const struct buffer *buf, char *ptr)
 {