mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-06 23:27:04 +02:00
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.
This commit is contained in:
parent
0e11d59af6
commit
e4d5a036ed
@ -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 */
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user