Showing
1 changed file
with
54 additions
and
0 deletions
include/cbuf.h
0 → 100644
| 1 | +/** | ||
| 2 | + * my implementation of a ringbuffer. | ||
| 3 | + * It maps a shared memory object twice directly following | ||
| 4 | + * thus make it possible to read and write from any | ||
| 5 | + * position within the buffer without the nasty wrap | ||
| 6 | + * calculations. | ||
| 7 | + * This is achived because the same memory region is mapped | ||
| 8 | + * at the two addresses. | ||
| 9 | + */ | ||
| 10 | +#ifndef __RINGBUFFER_H__ | ||
| 11 | +#define __RINGBUFFER_H__ | ||
| 12 | + | ||
| 13 | +#include <ctype.h> | ||
| 14 | +#include <string.h> | ||
| 15 | +#include <sys/types.h> | ||
| 16 | + | ||
| 17 | +#include "class.h" | ||
| 18 | + | ||
| 19 | +#define ECBUFOVFL 100 | ||
| 20 | + | ||
| 21 | + | ||
| 22 | +CLASS(Cbuf) { | ||
| 23 | + char * shm_name; // shared memory identifier | ||
| 24 | + | ||
| 25 | + char * data; | ||
| 26 | + char * mirror; | ||
| 27 | + | ||
| 28 | + size_t bsize; | ||
| 29 | + size_t bused; | ||
| 30 | + | ||
| 31 | + size_t write; | ||
| 32 | + size_t read; | ||
| 33 | +}; | ||
| 34 | + | ||
| 35 | +ssize_t cbufRead(Cbuf, int fd); | ||
| 36 | +ssize_t cbufWrite(Cbuf, int fd); | ||
| 37 | + | ||
| 38 | +char * cbufGetLine(Cbuf); | ||
| 39 | +char * cbufGetData(Cbuf, size_t); | ||
| 40 | +char * cbufSetData(Cbuf, const void *, size_t); | ||
| 41 | + | ||
| 42 | +char * cbufGetRead(Cbuf this); | ||
| 43 | +char * cbufGetWrite(Cbuf this); | ||
| 44 | +char * cbufMemchr(Cbuf this, int c); | ||
| 45 | +size_t cbufAddrIndex(Cbuf this, const void * c); | ||
| 46 | +void cbufIncRead(Cbuf this, size_t n); | ||
| 47 | +void cbufIncWrite(Cbuf this, size_t n); | ||
| 48 | +size_t cbufGetFree(Cbuf this); | ||
| 49 | +char cbufIsEmpty(Cbuf this); | ||
| 50 | +void cbufSkipNonAlpha(Cbuf this); | ||
| 51 | + | ||
| 52 | +#endif // __RINGBUFFER_H__ | ||
| 53 | + | ||
| 54 | +// vim: set ts=4 sw=4: |
Please
register
or
login
to post a comment