forked from memcached/memcached
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bipbuffer.h
87 lines (69 loc) · 2.07 KB
/
bipbuffer.h
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef BIPBUFFER_H
#define BIPBUFFER_H
typedef struct
{
unsigned long int size;
/* region A */
unsigned int a_start, a_end;
/* region B */
unsigned int b_end;
/* is B inuse? */
int b_inuse;
unsigned char data[];
} bipbuf_t;
/**
* Create a new bip buffer.
*
* malloc()s space
*
* @param[in] size The size of the buffer */
bipbuf_t *bipbuf_new(const unsigned int size);
/**
* Initialise a bip buffer. Use memory provided by user.
*
* No malloc()s are performed.
*
* @param[in] size The size of the array */
void bipbuf_init(bipbuf_t* me, const unsigned int size);
/**
* Free the bip buffer */
void bipbuf_free(bipbuf_t *me);
/* TODO: DOCUMENTATION */
unsigned char *bipbuf_request(bipbuf_t* me, const int size);
int bipbuf_push(bipbuf_t* me, const int size);
/**
* @param[in] data The data to be offered to the buffer
* @param[in] size The size of the data to be offered
* @return number of bytes offered */
int bipbuf_offer(bipbuf_t *me, const unsigned char *data, const int size);
/**
* Look at data. Don't move cursor
*
* @param[in] len The length of the data to be peeked
* @return data on success, NULL if we can't peek at this much data */
unsigned char *bipbuf_peek(const bipbuf_t* me, const unsigned int len);
/**
* Look at data. Don't move cursor
*
* @param[in] len The length of the data returned
* @return data on success, NULL if nothing available */
unsigned char *bipbuf_peek_all(const bipbuf_t* me, unsigned int *len);
/**
* Get pointer to data to read. Move the cursor on.
*
* @param[in] len The length of the data to be polled
* @return pointer to data, NULL if we can't poll this much data */
unsigned char *bipbuf_poll(bipbuf_t* me, const unsigned int size);
/**
* @return the size of the bipbuffer */
int bipbuf_size(const bipbuf_t* me);
/**
* @return 1 if buffer is empty; 0 otherwise */
int bipbuf_is_empty(const bipbuf_t* me);
/**
* @return how much space we have assigned */
int bipbuf_used(const bipbuf_t* cb);
/**
* @return bytes of unused space */
int bipbuf_unused(const bipbuf_t* me);
#endif /* BIPBUFFER_H */