rb_count¶
NAME¶
rb_count(3), rb_space(3), rb_peek_size(3) - get information about space available in ring buffer.
SYNOPSIS¶
#include <rb.h>
long rb_count(struct rb *rb);
long rb_space(struct rb *rb);
long rb_peek_size(struct rb *rb);
RETURN VALUE¶
rb_count(3) returns number of elements that are currently on the ring buffer. Tells you how much space is taken.
rb_space(3) return number of elements that can be copied to ring buffer. Tells you how much space is left on ring buffer.
rb_peek_size(3) return size (in bytes) of next frame that rb_read(3) will return. This only applies if rb was created with rb_dynamic flag.
ERROR¶
- EINVAL
Passed rb is invalid
EXAMPLE¶
Check used and free space on ring buffer
long space, count;
struct rb *rb;
rb = rb_new(8, 1, 0);
space = rb_space(rb); /* will return 7 */
count = rb_count(rb); /* will return 0 */
rb_write(rb, buf, 4); /* write 4 bytes to rb */
space = rb_space(rb); /* will return 3 */
count = rb_count(rb); /* will return 4 */
rb_write(rb, buf, 3); /* write 3 bytes to rb */
space = rb_space(rb); /* will return 0 */
count = rb_count(rb); /* will return 7 */
Check size of next frame on ring buffer
const char *s = "12345";
rb_write(rb, s, strlen(s));
size = rb_peek_size(rb); /* will return 5 */
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)