MINOR: buffer: replace buffer_full() with channel_full()

It's only used by channels since we need to know the amount of output
data.
This commit is contained in:
Willy Tarreau 2018-06-15 14:54:53 +02:00
parent 271e2a503d
commit 2375233ef0
4 changed files with 23 additions and 22 deletions

View File

@ -61,23 +61,6 @@ void buffer_dump(FILE *o, struct buffer *b, int from, int to);
/***** FIXME: OLD API BELOW *****/
/* Returns non-zero if the buffer's INPUT is considered full, which means that
* it holds at least as much INPUT data as (size - reserve). This also means
* that data that are scheduled for output are considered as potential free
* space, and that the reserved space is always considered as not usable. This
* information alone cannot be used as a general purpose free space indicator.
* However it accurately indicates that too many data were fed in the buffer
* for an analyzer for instance. See the channel_may_recv() function for a more
* generic function taking everything into account.
*/
static inline int buffer_full(const struct buffer *b, unsigned int reserve)
{
if (b == &buf_empty)
return 0;
return (b->i + reserve >= b->size);
}
/* Normalizes a pointer after a subtract */
static inline char *buffer_wrap_sub(const struct buffer *buf, char *ptr)
{

View File

@ -637,6 +637,24 @@ static inline int channel_recv_limit(const struct channel *chn)
return chn->buf->size - reserve;
}
/* Returns non-zero if the channel's INPUT buffer's is considered full, which
* means that it holds at least as much INPUT data as (size - reserve). This
* also means that data that are scheduled for output are considered as potential
* free space, and that the reserved space is always considered as not usable.
* This information alone cannot be used as a general purpose free space indicator.
* However it accurately indicates that too many data were fed in the buffer
* for an analyzer for instance. See the channel_may_recv() function for a more
* generic function taking everything into account.
*/
static inline int channel_full(const struct channel *c, unsigned int reserve)
{
if (c->buf == &buf_empty)
return 0;
return (b_data(c->buf) - co_data(c) + reserve >= c_size(c));
}
/* Returns the amount of space available at the input of the buffer, taking the
* reserved space into account if ->to_forward indicates that an end of transfer
* is close to happen. The test is optimized to avoid as many operations as

View File

@ -1717,7 +1717,7 @@ int http_wait_for_request(struct stream *s, struct channel *req, int an_bit)
* later, so the stream will never terminate. We
* must terminate it now.
*/
if (unlikely(buffer_full(req->buf, global.tune.maxrewrite))) {
if (unlikely(channel_full(req, global.tune.maxrewrite))) {
/* FIXME: check if URI is set and return Status
* 414 Request URI too long instead.
*/
@ -4177,7 +4177,7 @@ int http_wait_for_request_body(struct stream *s, struct channel *req, int an_bit
/* we get here if we need to wait for more data. If the buffer is full,
* we have the maximum we can expect.
*/
if (buffer_full(req->buf, global.tune.maxrewrite))
if (channel_full(req, global.tune.maxrewrite))
goto http_end;
if ((req->flags & CF_READ_TIMEOUT) || tick_is_expired(req->analyse_exp, now_ms)) {
@ -5211,7 +5211,7 @@ int http_wait_for_response(struct stream *s, struct channel *rep, int an_bit)
}
/* too large response does not fit in buffer. */
else if (buffer_full(rep->buf, global.tune.maxrewrite)) {
else if (channel_full(rep, global.tune.maxrewrite)) {
if (msg->err_pos < 0)
msg->err_pos = rep->buf->i;
goto hdr_response_bad;
@ -9530,7 +9530,7 @@ int smp_prefetch_http(struct proxy *px, struct stream *s, unsigned int opt,
/* Still no valid request ? */
if (unlikely(msg->msg_state < HTTP_MSG_BODY)) {
if ((msg->msg_state == HTTP_MSG_ERROR) ||
buffer_full(s->req.buf, global.tune.maxrewrite)) {
channel_full(&s->req, global.tune.maxrewrite)) {
return 0;
}
/* wait for final state */

View File

@ -122,7 +122,7 @@ int tcp_inspect_request(struct stream *s, struct channel *req, int an_bit)
* - if one rule returns KO, then return KO
*/
if ((req->flags & CF_SHUTR) || buffer_full(req->buf, global.tune.maxrewrite) ||
if ((req->flags & CF_SHUTR) || channel_full(req, global.tune.maxrewrite) ||
!s->be->tcp_req.inspect_delay || tick_is_expired(req->analyse_exp, now_ms))
partial = SMP_OPT_FINAL;
else