]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: buffer: replace buffer_full() with channel_full()
authorWilly Tarreau <w@1wt.eu>
Fri, 15 Jun 2018 12:54:53 +0000 (14:54 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 19 Jul 2018 14:23:41 +0000 (16:23 +0200)
It's only used by channels since we need to know the amount of output
data.

include/common/buffer.h
include/proto/channel.h
src/proto_http.c
src/tcp_rules.c

index 976ea0262903452c4066b195b7d6828196868d52..c0fdab40847283c1e6cc9def119a4b6161545baf 100644 (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)
 {
index 850f900dcd3c603340a87df3e7ae6738e2dd6cdf..18597e4feb9fb4f6699a255644f1640025ce9897 100644 (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
index 3d83e1b4b73a79bb111712b49781599f4d93da98..7f90373212583afd6d9b478c722dcb8f07434dc7 100644 (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 */
index deb34acf82cd87da288b95456783ec866916e0e1..e21c5b717f108d765696777e8d405dd918d7a277 100644 (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