]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] buffers: add buffer_cut_tail() to cut only unsent data
authorWilly Tarreau <w@1wt.eu>
Tue, 15 Sep 2009 19:22:24 +0000 (21:22 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 19 Sep 2009 12:53:47 +0000 (14:53 +0200)
This function is used to cut the "tail" of a buffer, which means strip it
to the length of unsent data only, and kill any remaining unsent data. Any
scheduled forwarding is stopped. This is mainly to be used to send error
messages after existing data. It does the same as buffer_erase() for buffers
without pending outgoing data.

include/proto/buffers.h

index a1834196a19fc4dcb372e3d28820e4f95124393a..3cde2092272e96ba23f74bdaf5d30970bfc6c238 100644 (file)
@@ -135,6 +135,30 @@ static inline void buffer_erase(struct buffer *buf)
                buf->flags &= ~BF_FULL;
 }
 
+/* Cut the "tail" of the buffer, which means strip it to the length of unsent
+ * data only, and kill any remaining unsent data. Any scheduled forwarding is
+ * stopped. This is mainly to be used to send error messages after existing
+ * data.
+ */
+static inline void buffer_cut_tail(struct buffer *buf)
+{
+       if (!buf->send_max)
+               return buffer_erase(buf);
+
+       buf->to_forward = 0;
+       if (buf->l == buf->send_max)
+               return;
+
+       buf->l = buf->send_max;
+       buf->r = buf->w + buf->l;
+       if (buf->r >= buf->data + buf->size)
+               buf->r -= buf->size;
+       buf->lr = buf->r;
+       buf->flags &= ~(BF_EMPTY|BF_FULL);
+       if (buf->l >= buf->max_len)
+               buf->flags |= BF_FULL;
+}
+
 /* marks the buffer as "shutdown" for reads and cancels the timeout */
 static inline void buffer_shutr(struct buffer *buf)
 {