QBRB.H(3)

πŸ’– QBRB.H β€” the ring buffer page, but make it make sense πŸ’–

okay bestie, this is qbrb.h, straight out of the libqb Programmer's Manual. it's a header, it's a whole vibe, and it's about to become your new hyperfixation. grab a snack. πŸ“


✨ NAME ✨

qbrb.h β€” this implements a ring buffer that works in "chunks", not bytes. periodt. πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

#include <qb/qbrb.h>

that's it. that's the whole synopsis. iconic. πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea: you write a complete chunk or you write nothing at all. no half-chunks, no lil byte-by-byte nibbling. it's giving all-or-nothing and honestly? respect. 😌

there are two types of ring buffer:

  • normal β€” this one will refuse to write a new chunk if the ring buffer is full. it's full, it said what it said, no more room bestie. πŸ’€
  • overwrite β€” this one will reclaim the oldest chunks inorder to make way for the new ones. out with the old, in with the new, main character energy only. ✨

this implementation is capable of working across processes, BUT β€” and this is the important part β€” one process must only write and the other process read. one writer, one reader. that's the arrangement. do not test it. πŸ™ˆ


🌸 the read process will do the following:

rb = qb_rb_open("test2", 2000, QB_RB_FLAG_SHARED_PROCESS|QB_RB_FLAG_CREATE);
for (i = 0; i < 200; i++) {
try_read_again:
    l = qb_rb_chunk_read(rb, (void *)out, 32, 1000);
    if (l < 0) {
        goto try_read_again;
    }
}
...
qb_rb_close(rb);

look at that goto hopping back like it's got somewhere to be. it does. it's retrying. we love a persistent queen. 🫢


🌈 the write process will do the following:

rb = qb_rb_open("test2", 2000, QB_RB_FLAG_SHARED_PROCESS);
for (i = 0; i < 200; i++) {
try_write_again:
    l = qb_rb_chunk_write(rb, &v, sizeof(v));
    if (l < sizeof(v)) {
        goto try_write_again;
    }
}
...
qb_rb_close(rb);

note how the writer did not pass QB_RB_FLAG_CREATE β€” because the reader already made it. teamwork, fr fr. 🧚

⚠️ reminder bestie: one process writes, the other reads. that's the whole deal. don't get cute with it.

πŸ‘‘ SEE ALSO πŸ‘‘

the whole friend group, go say hi:


Copyright (C) 2010-2020 Red Hat, Inc.


and that's the page bestie!! 🌟 it came from the LIBQB crew, dated 2025-09-16, and it lives at the address QBRB.H(3) β€” iykyk. go forth and buffer responsibly. mwah. πŸ’‹πŸ’–πŸŽ€

πŸ“¦ where this page comes from