mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-06 07:07:04 +02:00
MINOR: ring: add a function to compute max ring payload
Add a helper function to the ring API to compute the maximum payload length that could fit into the ring based on ring size.
This commit is contained in:
parent
06d36913bd
commit
5b295ff409
@ -41,6 +41,8 @@ int ring_attach_cli(struct ring *ring, struct appctx *appctx, uint flags);
|
||||
int cli_io_handler_show_ring(struct appctx *appctx);
|
||||
void cli_io_release_show_ring(struct appctx *appctx);
|
||||
|
||||
size_t ring_max_payload(const struct ring *ring);
|
||||
|
||||
#endif /* _HAPROXY_RING_H */
|
||||
|
||||
/*
|
||||
|
16
src/ring.c
16
src/ring.c
@ -457,6 +457,22 @@ void cli_io_release_show_ring(struct appctx *appctx)
|
||||
ring_detach_appctx(ring, appctx, ofs);
|
||||
}
|
||||
|
||||
/* Returns the MAXIMUM payload len that could theoretically fit into the ring
|
||||
* based on ring buffer size.
|
||||
*
|
||||
* Computation logic relies on implementation details from 'ring-t.h'.
|
||||
*/
|
||||
size_t ring_max_payload(const struct ring *ring)
|
||||
{
|
||||
size_t max;
|
||||
|
||||
/* initial max = bufsize - 1 (initial RC) - 1 (payload RC) */
|
||||
max = b_size(&ring->buf) - 1 - 1;
|
||||
|
||||
/* substract payload VI (varint-encoded size) */
|
||||
max -= varint_bytes(max);
|
||||
return max;
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
|
Loading…
Reference in New Issue
Block a user