From: Willy Tarreau Date: Tue, 13 Jan 2015 19:09:54 +0000 (+0100) Subject: MINOR: channel: add channel_in_transit() X-Git-Tag: v1.6-dev1~197 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1a4484dec8488cdd14c52e6cb93198e3c8f83942;p=thirdparty%2Fhaproxy.git MINOR: channel: add channel_in_transit() 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. --- diff --git a/include/proto/channel.h b/include/proto/channel.h index ca08ff1cf5..1648a6dad7 100644 --- a/include/proto/channel.h +++ b/include/proto/channel.h @@ -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.