]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: buffer: introduce b_realign_if_empty()
authorWilly Tarreau <w@1wt.eu>
Fri, 15 Jun 2018 15:50:15 +0000 (17:50 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 19 Jul 2018 14:23:39 +0000 (16:23 +0200)
Many places deal with buffer realignment after data removal. The method
is always the same : if the buffer is empty, set its pointer to the origin.
Let's have a function for this so that we have less code to change with the
new API.

include/common/buf.h

index 6d1a8c0bea613fc3ead29f14d82d3a7131184008..564e0ebad3dbd984d48e9e66c19977128a5b50da 100644 (file)
@@ -322,6 +322,13 @@ static inline void b_set_data(struct buffer *b, size_t len)
        }
 }
 
+/* b_realign_if_empty() : realigns a buffer if it's empty */
+static inline void b_realign_if_empty(struct buffer *b)
+{
+       if (!b_data(b))
+               b->p = b->data;
+}
+
 
 #endif /* _COMMON_BUF_H */