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:
Christopher Faulet 2023-11-17 11:09:45 +01:00
parent 7393bf7e42
commit 020231ea79

View File

@ -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().