taskrambler  v0.1.8
Web server and task management solution.
cbuf.h
Go to the documentation of this file.
1 /**
2  * \file
3  * My implementation of a ringbuffer.
4  * It maps a shared memory object twice directly following
5  * thus make it possible to read and write from any
6  * position within the buffer without the nasty wrap
7  * calculations.
8  * This is achived because the same memory region is mapped
9  * at the two addresses.
10  *
11  * \author Georg Hopp
12  *
13  * \copyright
14  * Copyright © 2012 Georg Hopp
15  *
16  * This program is free software: you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation, either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program. If not, see <http://www.gnu.org/licenses/>.
28  */
29 
30 #ifndef __CBUF_H__
31 #define __CBUF_H__
32 
33 #include <ctype.h>
34 #include <string.h>
35 #include <sys/types.h>
36 
37 #include "class.h"
38 #include "stream.h"
39 
40 #include "commons.h"
41 #include "utils/memory.h"
42 
43 #define ECBUFOVFL 100
44 
45 
46 CLASS(Cbuf) {
47  char * shm_name; // shared memory identifier
48 
49  char * data;
50  Bool lock;
51 
52  size_t bsize;
53  size_t bused;
54 
55  size_t write;
56  size_t read;
57 };
58 
59 ssize_t cbufRead(Cbuf, Stream);
60 ssize_t cbufWrite(Cbuf, Stream);
61 
62 char * cbufGetLine(Cbuf, char **);
63 char * cbufGetData(Cbuf, size_t);
64 char * cbufSetData(Cbuf, const void *, size_t);
65 void cbufEmpty(Cbuf);
66 
67 char * cbufGetRead(Cbuf this);
68 char * cbufGetWrite(Cbuf this);
69 char * cbufMemchr(Cbuf this, int c);
70 size_t cbufAddrIndex(Cbuf this, const void * c);
71 void cbufIncRead(Cbuf this, size_t n);
72 void cbufIncWrite(Cbuf this, size_t n);
73 size_t cbufGetFree(Cbuf this);
74 char cbufIsEmpty(Cbuf this);
75 void cbufSkipNonAlpha(Cbuf this);
76 Bool cbufIsLocked(Cbuf this);
77 void cbufLock(Cbuf this);
78 void cbufRelease(Cbuf this);
79 
80 #endif // __CBUF_H__
81 
82 // vim: set ts=4 sw=4:
char cbufIsEmpty(Cbuf this)
Definition: is_empty.c:26
CLASS(Cbuf)
Definition: cbuf.h:46
size_t cbufGetFree(Cbuf this)
Definition: get_free.c:28
char * cbufGetData(Cbuf, size_t)
Definition: get_data.c:29
char * cbufSetData(Cbuf, const void *, size_t)
Definition: set_data.c:30
void cbufLock(Cbuf this)
Definition: lock.c:26
void cbufEmpty(Cbuf)
Definition: empty.c:26
void cbufRelease(Cbuf this)
Definition: release.c:26
char * cbufMemchr(Cbuf this, int c)
Definition: memchr.c:28
Bool cbufIsLocked(Cbuf this)
Definition: is_locked.c:28
ssize_t cbufWrite(Cbuf, Stream)
char * cbufGetWrite(Cbuf this)
Definition: get_write.c:26
#define Bool
Definition: commons.h:26
void cbufIncWrite(Cbuf this, size_t n)
Definition: inc_write.c:28
int data
Definition: binarytree.c:7
ssize_t cbufRead(Cbuf, Stream)
Definition: cbuf/read.c:32
char * cbufGetLine(Cbuf, char **)
Definition: get_line.c:30
size_t cbufAddrIndex(Cbuf this, const void *c)
Definition: addr_index.c:28
void cbufIncRead(Cbuf this, size_t n)
Definition: inc_read.c:28
char * cbufGetRead(Cbuf this)
Definition: get_read.c:26
void cbufSkipNonAlpha(Cbuf this)