rb_set_hard_max_count¶
NAME¶
rb_new(3), rb_init(3) - initialize new ring buffer
SYNOPSIS¶
#include <rb.h>
int rb_set_hard_max_count(struct rb *rb, size_t count);
DESCRIPTION¶
rb_set_hard_max_count(3) will set a hard limit for growing rb. If rb has not been created with rb_growable this function does nothing.
After init there is no limit how big rb can get. If you keep putting data on rb, it will grow memory until memory is exhausted. You can limit the grow with this function. Once limit is hit, function will fall back into non-growable mode. count must be power of 2 number just like when passing to rb_new(3).
RETURN VALUE¶
Function will return 0 on success or -1 on errors.
ERROR¶
- EINVAL
count is not a power of 2 number, or rb is NULL.
EXAMPLE¶
struct rb *rb = rb_new(4, 1, rb_growable);
rb_set_hard_max_count(rb, 8);
rb_write(rb, buf, 7); /* rb will grow */
rb_write(rb, buf, 7); /* won't grow anymore, EAGAIN return */
rb_set_hard_max_count(rb, 16);
rb_write(rb, buf, 7); /* rb can grow again */
SEE ALSO¶
rb_new(3), rb_init(3), rb_destroy(3), rb_cleanup(3), rb_write(3), rb_send(3), rb_writev(3), rb_sendv(3), rb_read(3), rb_recv(3), rb_readv(3), rb_recvv(3), rb_read_claim(3), rb_read_commit(3), rb_write_claim(3), rb_write_commit(3), rb_clear(3), rb_discard(3), rb_count(3), rb_space(3), rb_stop(3), rb_peek_size(3), rb_set_hard_max_count(3)