diff --git a/include/cbuf.h b/include/cbuf.h new file mode 100644 index 0000000..63e2117 --- /dev/null +++ b/include/cbuf.h @@ -0,0 +1,54 @@ +/** + * my implementation of a ringbuffer. + * It maps a shared memory object twice directly following + * thus make it possible to read and write from any + * position within the buffer without the nasty wrap + * calculations. + * This is achived because the same memory region is mapped + * at the two addresses. + */ +#ifndef __RINGBUFFER_H__ +#define __RINGBUFFER_H__ + +#include +#include +#include + +#include "class.h" + +#define ECBUFOVFL 100 + + +CLASS(Cbuf) { + char * shm_name; // shared memory identifier + + char * data; + char * mirror; + + size_t bsize; + size_t bused; + + size_t write; + size_t read; +}; + +ssize_t cbufRead(Cbuf, int fd); +ssize_t cbufWrite(Cbuf, int fd); + +char * cbufGetLine(Cbuf); +char * cbufGetData(Cbuf, size_t); +char * cbufSetData(Cbuf, const void *, size_t); + +char * cbufGetRead(Cbuf this); +char * cbufGetWrite(Cbuf this); +char * cbufMemchr(Cbuf this, int c); +size_t cbufAddrIndex(Cbuf this, const void * c); +void cbufIncRead(Cbuf this, size_t n); +void cbufIncWrite(Cbuf this, size_t n); +size_t cbufGetFree(Cbuf this); +char cbufIsEmpty(Cbuf this); +void cbufSkipNonAlpha(Cbuf this); + +#endif // __RINGBUFFER_H__ + +// vim: set ts=4 sw=4: