]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: buffers: add a rewind function
authorWilly Tarreau <w@1wt.eu>
Fri, 18 May 2012 20:11:27 +0000 (22:11 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 18 May 2012 20:11:27 +0000 (22:11 +0200)
b_rew() will be used to rewind a buffer for certain specific operations
such as header inspection on data already in the output queue.

include/proto/buffers.h

index 6f8e2c15d430432e68c0eb79dd5875b782970d1d..66c6e61782b6b7ea28f9ec967a1f6dc4016eea64 100644 (file)
@@ -303,6 +303,19 @@ static inline void b_adv(struct buffer *b, unsigned int adv)
        b->p = b_ptr(b, adv);
 }
 
+/* Rewinds the buffer by <adv> bytes, which means that the buffer pointer goes
+ * backwards, and that as many bytes from out are moved to in. The caller is
+ * responsible for ensuring that adv is always smaller than or equal to b->o.
+ */
+static inline void b_rew(struct buffer *b, unsigned int adv)
+{
+       b->i += adv;
+       b->o -= adv;
+       if (!b->o && !b->pipe)
+               b->flags |= BF_OUT_EMPTY;
+       b->p = b_ptr(b, -adv);
+}
+
 /* Return the amount of bytes that can be written into the buffer at once,
  * excluding the amount of reserved space passed in <res>, which is
  * preserved.