From: Willy Tarreau Date: Mon, 2 May 2016 14:05:10 +0000 (+0200) Subject: MINOR: channel: add new function channel_congested() X-Git-Tag: v1.7-dev3~13 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=55e58f23348c2f9fa918e7370c0ddb98b307ee28;p=thirdparty%2Fhaproxy.git MINOR: channel: add new function channel_congested() This function returns non-zero if the channel is congested with data in transit waiting for leaving, indicating to the caller that it should wait for the reserve to be released before starting to process new data in case it needs the ability to append data. This is meant to be used while waiting for a clean response buffer before processing a request. --- diff --git a/include/proto/channel.h b/include/proto/channel.h index e6d2f3e402..22f28fcc10 100644 --- a/include/proto/channel.h +++ b/include/proto/channel.h @@ -149,6 +149,27 @@ static inline int channel_is_rewritable(const struct channel *chn) return rem >= 0; } +/* Returns non-zero if the channel is congested with data in transit waiting + * for leaving, indicating to the caller that it should wait for the reserve to + * be released before starting to process new data in case it needs the ability + * to append data. This is meant to be used while waiting for a clean response + * buffer before processing a request. + */ +static inline int channel_congested(const struct channel *chn) +{ + if (!chn->buf->o) + return 0; + + if (!channel_is_rewritable(chn)) + return 1; + + if (chn->buf->p + chn->buf->i > + chn->buf->data + chn->buf->size - global.tune.maxrewrite) + return 1; + + return 0; +} + /* Tells whether data are likely to leave the buffer. This is used to know when * we can safely ignore the reserve since we know we cannot retry a connection. * It returns zero if data are blocked, non-zero otherwise.