mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-06 23:27:04 +02:00
MINOR: channel: Add functions to get info on buffers and deal with HTX streams
This patch adds HXT-aware versions of the functions c_data(), ci_data() and c_empty(). channel_data() function returns the amount of data in the channel, channel_input_data() returns the amount of input data and channel_empty() returns true if the channel's buffer is empty. These functions handles HTX buffers. In addition, channel_data_limit() function, still HTX-aware, can be used to get the maximum absolute amount of data that can be copied in a buffer, independently on data already present in the buffer.
This commit is contained in:
parent
7393bf7e42
commit
020231ea79
@ -782,6 +782,43 @@ static inline int channel_recv_max(const struct channel *chn)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Returns the maximum absolute amount of data that can be copied in a channel,
|
||||
* taking the reserved space into account but also the HTX overhead for HTX
|
||||
* streams.
|
||||
*/
|
||||
static inline size_t channel_data_limit(const struct channel *chn)
|
||||
{
|
||||
size_t max = (global.tune.bufsize - global.tune.maxrewrite);
|
||||
|
||||
if (IS_HTX_STRM(chn_strm(chn)))
|
||||
max -= HTX_BUF_OVERHEAD;
|
||||
return max;
|
||||
}
|
||||
|
||||
/* Returns the amount of data in a channel, taking the HTX streams into
|
||||
* account. For raw channels, it is equivalent to c_data. For HTX channels, we
|
||||
* rely on the HTX api.
|
||||
*/
|
||||
static inline size_t channel_data(const struct channel *chn)
|
||||
{
|
||||
return (IS_HTX_STRM(chn_strm(chn)) ? htx_used_space(htxbuf(&chn->buf)) : c_data(chn));
|
||||
}
|
||||
|
||||
/* Returns the amount of input data in a channel, taking he HTX streams into
|
||||
* account. This function relies on channel_data().
|
||||
*/
|
||||
static inline size_t channel_input_data(const struct channel *chn)
|
||||
{
|
||||
return channel_data(chn) - co_data(chn);
|
||||
}
|
||||
|
||||
/* Returns 1 if the channel is empty, taking he HTX streams into account */
|
||||
static inline size_t channel_empty(const struct channel *chn)
|
||||
{
|
||||
return (IS_HTX_STRM(chn) ? htx_is_empty(htxbuf(&chn->buf)) : c_empty(chn));
|
||||
}
|
||||
|
||||
|
||||
/* 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().
|
||||
|
Loading…
Reference in New Issue
Block a user