cbuf.h
1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* 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 <ctype.h>
#include <string.h>
#include <sys/types.h>
#include "class.h"
#define ECBUFOVFL 100
#ifndef TRUE
#define TRUE ((void *)1)
#endif
#ifndef FALSE
#define FALSE ((void *)0)
#endif
CLASS(Cbuf) {
char * shm_name; // shared memory identifier
char * data;
void * lock;
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);
void * cbufIsLocked(Cbuf this);
void cbufLock(Cbuf this);
void cbufRelease(Cbuf this);
#endif // __RINGBUFFER_H__
// vim: set ts=4 sw=4: