]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: buffer: merge b{i,o}_contig_space()
authorWilly Tarreau <w@1wt.eu>
Thu, 7 Jun 2018 16:58:07 +0000 (18:58 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 19 Jul 2018 14:23:40 +0000 (16:23 +0200)
These ones were merged into a single b_contig_space() that covers both
(the bo_ case was a simplified version of the other one). The function
doesn't use ->i nor ->o anymore.

include/common/buf.h
include/common/buffer.h
src/channel.c
src/mux_h2.c

index 0ee9c54748c713c8d4d4b8bd708744425a468faa..33830f7097179b9065be8dff8336190e2f0c78df 100644 (file)
@@ -293,6 +293,24 @@ static inline size_t b_contig_data(const struct buffer *b, size_t start)
        return data;
 }
 
+/* b_contig_space() : returns the amount of bytes that can be appended to the
+ * buffer at once.
+ */
+static inline size_t b_contig_space(const struct buffer *b)
+{
+       const char *left, *right;
+
+       right = b_head(b);
+       left  = right + b_data(b);
+
+       if (left >= b_wrap(b))
+               left -= b_size(b);
+       else
+               right = b_wrap(b);
+
+       return right - left;
+}
+
 
 /*********************************************/
 /* Functions used to modify the buffer state */
index 8638bd6849eaa677c208a5fe91ba52481fe9435b..10ff640b50f7c0f102c72dc97e7f596c53b357e4 100644 (file)
@@ -105,46 +105,6 @@ static inline void bo_del(struct buffer *b, unsigned int del)
        b->o -= del;
 }
 
-/* Return the amount of bytes that can be written into the input area at once
- * including reserved space which may be overwritten (this is the caller
- * responsibility to know if the reserved space is protected or not).
-*/
-static inline int bi_contig_space(const struct buffer *b)
-{
-       const char *left, *right;
-
-       left  = b->p + b->i;
-       right = b->p - b->o;
-       if (left >= b->data + b->size)
-               left -= b->size;
-       else {
-               if (right < b->data)
-                       right += b->size;
-               else
-                       right = b->data + b->size;
-       }
-       return (right - left);
-}
-
-/* Return the amount of bytes that can be written into the output area at once
- * including reserved space which may be overwritten (this is the caller
- * responsibility to know if the reserved space is protected or not). Input data
- * are assumed to not exist.
-*/
-static inline int bo_contig_space(const struct buffer *b)
-{
-       const char *left, *right;
-
-       left  = b->p;
-       right = b->p - b->o;
-       if (right < b->data)
-               right += b->size;
-       else
-               right = b->data + b->size;
-
-       return (right - left);
-}
-
 /* Return the buffer's length in bytes by summing the input and the output */
 static inline int buffer_len(const struct buffer *buf)
 {
@@ -334,7 +294,7 @@ static inline int bo_putblk(struct buffer *b, const char *blk, int len)
        if (!len)
                return 0;
 
-       half = bo_contig_space(b);
+       half = b_contig_space(b);
        if (half > len)
                half = len;
 
@@ -444,7 +404,7 @@ static inline int bi_putblk(struct buffer *b, const char *blk, int len)
        if (!len)
                return 0;
 
-       half = bi_contig_space(b);
+       half = b_contig_space(b);
        if (half > len)
                half = len;
 
index 62a860b5c9b7a339c9c532a87bdaf2a769000055..fc1bf1279ef25e658f26e4f5f4136b1533184f81 100644 (file)
@@ -92,7 +92,7 @@ int co_inject(struct channel *chn, const char *msg, int len)
        }
 
        c_realign_if_empty(chn);
-       max = bo_contig_space(chn->buf);
+       max = b_contig_space(chn->buf);
        if (len > max)
                return max;
 
@@ -166,7 +166,7 @@ int ci_putblk(struct channel *chn, const char *blk, int len)
                return 0;
 
        /* OK so the data fits in the buffer in one or two blocks */
-       max = bi_contig_space(chn->buf);
+       max = b_contig_space(chn->buf);
        memcpy(ci_tail(chn), blk, MIN(len, max));
        if (len > max)
                memcpy(chn->buf->data, blk + max, len - max);
index e2f96c7b8ee99a0c9769fd496c43473c4105c371..028427915e81bd2dde97f5e91ed0c6feaf1da6d1 100644 (file)
@@ -2989,7 +2989,7 @@ static int h2s_frt_make_resp_headers(struct h2s *h2s, struct buffer *buf)
 
        while (1) {
                outbuf.str  = b_tail(h2c->mbuf);
-               outbuf.size = bo_contig_space(h2c->mbuf);
+               outbuf.size = b_contig_space(h2c->mbuf);
                outbuf.len = 0;
 
                if (outbuf.size >= 9 || !b_space_wraps(h2c->mbuf))
@@ -3147,7 +3147,7 @@ static int h2s_frt_make_resp_data(struct h2s *h2s, struct buffer *buf)
 
        while (1) {
                outbuf.str  = b_tail(h2c->mbuf);
-               outbuf.size = bo_contig_space(h2c->mbuf);
+               outbuf.size = b_contig_space(h2c->mbuf);
                outbuf.len = 0;
 
                if (outbuf.size >= 9 || !b_space_wraps(h2c->mbuf))