From: Willy Tarreau Date: Thu, 7 Jun 2018 16:58:07 +0000 (+0200) Subject: MINOR: buffer: merge b{i,o}_contig_space() X-Git-Tag: v1.9-dev1~144 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e4d5a036ed60cad8ea8ef849a40d5474ef3c3364;p=thirdparty%2Fhaproxy.git MINOR: buffer: merge b{i,o}_contig_space() 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. --- diff --git a/include/common/buf.h b/include/common/buf.h index 0ee9c54748..33830f7097 100644 --- a/include/common/buf.h +++ b/include/common/buf.h @@ -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 */ diff --git a/include/common/buffer.h b/include/common/buffer.h index 8638bd6849..10ff640b50 100644 --- a/include/common/buffer.h +++ b/include/common/buffer.h @@ -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; diff --git a/src/channel.c b/src/channel.c index 62a860b5c9..fc1bf1279e 100644 --- a/src/channel.c +++ b/src/channel.c @@ -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); diff --git a/src/mux_h2.c b/src/mux_h2.c index e2f96c7b8e..028427915e 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -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))