From: Willy Tarreau Date: Fri, 15 Jun 2018 12:54:53 +0000 (+0200) Subject: MINOR: buffer: replace buffer_full() with channel_full() X-Git-Tag: v1.9-dev1~117 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2375233ef0e2a17996d46a2c85ed3ab90bed1478;p=thirdparty%2Fhaproxy.git MINOR: buffer: replace buffer_full() with channel_full() It's only used by channels since we need to know the amount of output data. --- diff --git a/include/common/buffer.h b/include/common/buffer.h index 976ea02629..c0fdab4084 100644 --- a/include/common/buffer.h +++ b/include/common/buffer.h @@ -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) { diff --git a/include/proto/channel.h b/include/proto/channel.h index 850f900dcd..18597e4feb 100644 --- a/include/proto/channel.h +++ b/include/proto/channel.h @@ -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 diff --git a/src/proto_http.c b/src/proto_http.c index 3d83e1b4b7..7f90373212 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -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 */ diff --git a/src/tcp_rules.c b/src/tcp_rules.c index deb34acf82..e21c5b717f 100644 --- a/src/tcp_rules.c +++ b/src/tcp_rules.c @@ -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