]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: channel: add channel_in_transit()
authorWilly Tarreau <w@1wt.eu>
Tue, 13 Jan 2015 19:09:54 +0000 (20:09 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 14 Jan 2015 12:51:48 +0000 (13:51 +0100)
This function returns the amount of bytes in transit in a channel's buffer,
which is the amount of outgoing data plus the amount of incoming data bound
to the forward limit.

include/proto/channel.h

index ca08ff1cf5c0fdc7a40f8e158fad831d8f3296cb..1648a6dad7d4ec732878669e9440af36a09afc91 100644 (file)
@@ -117,6 +117,27 @@ static inline int channel_reserved(const struct channel *chn)
        return rem >= 0;
 }
 
+/* Returns the amount of bytes from the channel that are already scheduled for
+ * leaving (buf->o) or that are still part of the input and expected to be sent
+ * soon as covered by to_forward. This is useful to know by how much we can
+ * shrink the rewrite reserve during forwards.
+ */
+static inline int channel_in_transit(const struct channel *chn)
+{
+       int ret;
+
+       /* below, this is min(i, to_forward) optimized for the fast case */
+       if (chn->to_forward >= chn->buf->i ||
+           (CHN_INFINITE_FORWARD < MAX_RANGE(typeof(chn->buf->i)) &&
+            chn->to_forward == CHN_INFINITE_FORWARD))
+               ret = chn->buf->i;
+       else
+               ret = chn->to_forward;
+
+       ret += chn->buf->o;
+       return ret;
+}
+
 /* Returns non-zero if the buffer input is considered full. This is used to
  * decide when to stop reading into a buffer when we want to ensure that we
  * leave the reserve untouched after all pending outgoing data are forwarded.