ost::Buffer(3)
π ost::Buffer π β Library Functions Manual
okay bestie, grab a snack and your emotional support iced coffee, because today we're unpacking ost::Buffer from GNU CommonC++ π«Ά β that's the C++ class chillin' in section 3 of the manual (library functions, iykyk). She's abstract, she's threaded, she's lowkey the backbone of inter-thread gossip. Let's go. β¨
πΈ NAME πΈ
ost::Buffer β the buffer class, and she is the moment: an IPC service built upon a buffer of fixed capacity that can be used to transfer objects between one or more producer and consumer threads. no cap. π
π SYNOPSIS π
#include <buffer.h>
Inherits ost::Conditional.
Inherited by ost::FixedBuffer.
π Public Member Functions
Buffer (size_t capacity)β create a buffer object of known capacity πvirtual ~Buffer ()β in derived functions, may be used to free the actual memory used to hold buffered datasize_t getSize (void)β return the capacity of the buffer as specified at creationsize_t getUsed (void)β return the current capacity in use for the buffersize_t wait (void *buf, timeout_t timeout=0)β let one or more threads wait for an object to become available in the buffersize_t post (void *buf, timeout_t timeout=0)β post an object into the buffer and enable a waiting thread to receive itsize_t peek (void *buf)β peek at the current content (first object) in the buffervirtual bool isValid (void)β new virtual to test if buffer is a valid object
β Static Public Attributes
static const size_t timeoutβ value to return when a timed operation returned with a timeout
π¦ Protected Member Functions
virtual size_t onPeek (void *buf)=0β invoke derived class buffer peeking methodvirtual size_t onWait (void *buf)=0β invoke derived class object request from buffervirtual size_t onPost (void *buf)=0β invoke derived class posting of object to buffer
π Related Functions
(Note that these are not member functions.)
size_t get (Buffer &b, void *o, timeout_t t=0)size_t put (Buffer &b, void *o, timeout_t t=0)size_t peek (Buffer &b, void *o)
π Detailed Description π
The buffer class represents an IPC service that is built upon a buffer of fixed capacity that can be used to transfer objects between one or more producer and consumer threads. it's giving β¨message passingβ¨
Producer threads post objects into the buffer, and consumer threads wait for and receive objects from the buffer. Semaphores are used to block the buffer from overflowing and indicate when there is data available, and mutexes are used to protect multiple consumers and producer threads from stepping over each other. teamwork, bestie. π«Ά
The buffer class is an abstract class in that the actual data being buffered is not directly specified within the buffer class itself. The buffer class should be used as a base class for a class that actually implements buffering and which may be aware of the data types actually are being buffered. A template class could be created based on buffer for this purpose. Another possibility is to create a class derived from both Thread and Buffer which can be used to implement message passing threads. π
Author David Sugar dyfet@ostel.com
Producer/Consumer buffer for use between threads.
π§ Constructor & Destructor Documentation π§
π ost::Buffer::Buffer (size_t capacity)
Create a buffer object of known capacity. iconic.
Parameters
- capacity is the integer capacity of the buffer.
π virtual ost::Buffer::~Buffer () [virtual]
In derived functions, may be used to free the actual memory used to hold buffered data. clean up after yourself, queen π
π₯ Member Function Documentation π₯
π size_t ost::Buffer::getSize (void) [inline]
Return the capacity of the buffer as specified at creation.
Returns
- size of buffer.
π size_t ost::Buffer::getUsed (void) [inline]
Return the current capacity in use for the buffer. Free space is technically getSize() - getUsed(). do with that math what you will π
Returns
- integer used capacity of the buffer.
See also
getSize
π virtual bool ost::Buffer::isValid (void) [virtual]
New virtual to test if buffer is a valid object. vibe check, basically β
Returns
trueif object is valid.
Reimplemented in ost::FixedBuffer.
π virtual size_t ost::Buffer::onPeek (void * buf) [protected], [pure virtual]
Invoke derived class buffer peeking method.
Returns
- size of object found.
Parameters
- buf pointer to copy contents of head of buffer to.
Implemented in ost::FixedBuffer.
π virtual size_t ost::Buffer::onPost (void * buf) [protected], [pure virtual]
Invoke derived class posting of object to buffer.
Returns
- size of object posted.
Parameters
- buf pointer to object being posted to the buffer.
Implemented in ost::FixedBuffer.
π virtual size_t ost::Buffer::onWait (void * buf) [protected], [pure virtual]
Invoke derived class object request from buffer.
Returns
- size of object returned.
Parameters
- buf pointer to hold object returned from the buffer.
Implemented in ost::FixedBuffer.
π size_t ost::Buffer::peek (void * buf)
Peek at the current content (first object) in the buffer. just a lil look, no touching π
Returns
- size of object in the buffer.
Parameters
- buf pointer to store object found in the buffer.
Referenced by peek().
π size_t ost::Buffer::post (void * buf, timeout_t timeout = 0)
Post an object into the buffer and enable a waiting thread to receive it.
Returns
- size of object posted in bytes.
Parameters
- buf pointer to object to store in the buffer.
- timeout time to wait.
Referenced by put().
π size_t ost::Buffer::wait (void * buf, timeout_t timeout = 0)
Let one or more threads wait for an object to become available in the buffer. The waiting thread(s) will wait forever if no object is ever placed into the buffer.
β οΈ fr fr, bestie β forever means forever here. if nothing ever gets posted, those threads are just gonna sit there. not a drill. π
Returns
- size of object passed by buffer in bytes.
Parameters
- buf pointer to store object retrieved from the buffer.
- timeout time to wait.
Referenced by get().
π Friends And Related Function Documentation π
π¦ size_t get (Buffer & b, void * o, timeout_t t = 0) [related]
References wait().
π¦ size_t peek (Buffer & b, void * o) [related]
Examples
SampleSocketPort.cpp.
References peek().
π¦ size_t put (Buffer & b, void * o, timeout_t t = 0) [related]
References post().
π Member Data Documentation π
β const size_t ost::Buffer::timeout [static]
value to return when a timed operation returned with a timeout. she's the "oops, ran out of patience" flag π
π Author π
Generated automatically by Doxygen for GNU CommonC++ from the source code.
and that's the whole page, bestie, you ate it πβ¨ this was GNU CommonC++, dated Sun Dec 27 2020, and she lives at ost::Buffer(3) β go forth and buffer responsibly ππ¦π
π¦ where this page comes from
- ubuntu jammy: libcommoncpp2-doc 1.8.1-10
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms