mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-21 13:51:26 +02:00
MINOR: buffer: replace bi_space_for_replace() with ci_space_for_replace()
This one computes the size that can be overwritten over the input part of the buffer, so it's channel-specific.
This commit is contained in:
parent
2375233ef0
commit
3f6799975f
@ -77,32 +77,6 @@ static inline char *buffer_wrap_add(const struct buffer *buf, char *ptr)
|
|||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns the amount of byte that can be written starting from <p> into the
|
|
||||||
* input buffer at once, including reserved space which may be overwritten.
|
|
||||||
* This is used by Lua to insert data in the input side just before the other
|
|
||||||
* data using buffer_replace(). The goal is to transfer these new data in the
|
|
||||||
* output buffer.
|
|
||||||
*/
|
|
||||||
static inline int bi_space_for_replace(const struct buffer *buf)
|
|
||||||
{
|
|
||||||
const char *end;
|
|
||||||
|
|
||||||
/* If the input side data overflows, we cannot insert data contiguously. */
|
|
||||||
if (buf->p + buf->i >= buf->data + buf->size)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
/* Check the last byte used in the buffer, it may be a byte of the output
|
|
||||||
* side if the buffer wraps, or its the end of the buffer.
|
|
||||||
*/
|
|
||||||
end = buffer_wrap_sub(buf, buf->p - buf->o);
|
|
||||||
if (end <= buf->p)
|
|
||||||
end = buf->data + buf->size;
|
|
||||||
|
|
||||||
/* Compute the amount of bytes which can be written. */
|
|
||||||
return end - (buf->p + buf->i);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Normalizes a pointer which is supposed to be relative to the beginning of a
|
/* Normalizes a pointer which is supposed to be relative to the beginning of a
|
||||||
* buffer, so that wrapping is correctly handled. The intent is to use this
|
* buffer, so that wrapping is correctly handled. The intent is to use this
|
||||||
* when increasing a pointer. Note that the wrapping test is only performed
|
* when increasing a pointer. Note that the wrapping test is only performed
|
||||||
|
@ -670,6 +670,31 @@ static inline int channel_recv_max(const struct channel *chn)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Returns the amount of bytes that can be written over the input data at once,
|
||||||
|
* including reserved space which may be overwritten. This is used by Lua to
|
||||||
|
* insert data in the input side just before the other data using buffer_replace().
|
||||||
|
* The goal is to transfer these new data in the output buffer.
|
||||||
|
*/
|
||||||
|
static inline int ci_space_for_replace(const struct channel *chn)
|
||||||
|
{
|
||||||
|
const struct buffer *buf = chn->buf;
|
||||||
|
const char *end;
|
||||||
|
|
||||||
|
/* If the input side data overflows, we cannot insert data contiguously. */
|
||||||
|
if (b_head(buf) + b_data(buf) >= b_wrap(buf))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* Check the last byte used in the buffer, it may be a byte of the output
|
||||||
|
* side if the buffer wraps, or its the end of the buffer.
|
||||||
|
*/
|
||||||
|
end = b_head(buf);
|
||||||
|
if (end <= ci_head(chn))
|
||||||
|
end = b_wrap(buf);
|
||||||
|
|
||||||
|
/* Compute the amount of bytes which can be written. */
|
||||||
|
return end - ci_tail(chn);
|
||||||
|
}
|
||||||
|
|
||||||
/* Allocates a buffer for channel <chn>, but only if it's guaranteed that it's
|
/* Allocates a buffer for channel <chn>, but only if it's guaranteed that it's
|
||||||
* not the last available buffer or it's the response buffer. Unless the buffer
|
* not the last available buffer or it's the response buffer. Unless the buffer
|
||||||
* is the response buffer, an extra control is made so that we always keep
|
* is the response buffer, an extra control is made so that we always keep
|
||||||
|
@ -3040,7 +3040,7 @@ __LJMP static int hlua_channel_send_yield(lua_State *L, int status, lua_KContext
|
|||||||
/* The buffer avalaible size may be not contiguous. This test
|
/* The buffer avalaible size may be not contiguous. This test
|
||||||
* detects a non contiguous buffer and realign it.
|
* detects a non contiguous buffer and realign it.
|
||||||
*/
|
*/
|
||||||
if (bi_space_for_replace(chn->buf) < max)
|
if (ci_space_for_replace(chn) < max)
|
||||||
channel_slow_realign(chn, trash.str);
|
channel_slow_realign(chn, trash.str);
|
||||||
|
|
||||||
/* Copy input data in the buffer. */
|
/* Copy input data in the buffer. */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user