xref: /memcached-1.4.29/bipbuffer.h (revision 916fff36)
1 #ifndef BIPBUFFER_H
2 #define BIPBUFFER_H
3 
4 typedef struct
5 {
6     unsigned long int size;
7 
8     /* region A */
9     unsigned int a_start, a_end;
10 
11     /* region B */
12     unsigned int b_end;
13 
14     /* is B inuse? */
15     int b_inuse;
16 
17     unsigned char data[];
18 } bipbuf_t;
19 
20 /**
21  * Create a new bip buffer.
22  *
23  * malloc()s space
24  *
25  * @param[in] size The size of the buffer */
26 bipbuf_t *bipbuf_new(const unsigned int size);
27 
28 /**
29  * Initialise a bip buffer. Use memory provided by user.
30  *
31  * No malloc()s are performed.
32  *
33  * @param[in] size The size of the array */
34 void bipbuf_init(bipbuf_t* me, const unsigned int size);
35 
36 /**
37  * Free the bip buffer */
38 void bipbuf_free(bipbuf_t *me);
39 
40 /* TODO: DOCUMENTATION */
41 unsigned char *bipbuf_request(bipbuf_t* me, const int size);
42 int bipbuf_push(bipbuf_t* me, const int size);
43 
44 /**
45  * @param[in] data The data to be offered to the buffer
46  * @param[in] size The size of the data to be offered
47  * @return number of bytes offered */
48 int bipbuf_offer(bipbuf_t *me, const unsigned char *data, const int size);
49 
50 /**
51  * Look at data. Don't move cursor
52  *
53  * @param[in] len The length of the data to be peeked
54  * @return data on success, NULL if we can't peek at this much data */
55 unsigned char *bipbuf_peek(const bipbuf_t* me, const unsigned int len);
56 
57 /**
58  * Look at data. Don't move cursor
59  *
60  * @param[in] len The length of the data returned
61  * @return data on success, NULL if nothing available */
62 unsigned char *bipbuf_peek_all(const bipbuf_t* me, unsigned int *len);
63 
64 /**
65  * Get pointer to data to read. Move the cursor on.
66  *
67  * @param[in] len The length of the data to be polled
68  * @return pointer to data, NULL if we can't poll this much data */
69 unsigned char *bipbuf_poll(bipbuf_t* me, const unsigned int size);
70 
71 /**
72  * @return the size of the bipbuffer */
73 int bipbuf_size(const bipbuf_t* me);
74 
75 /**
76  * @return 1 if buffer is empty; 0 otherwise */
77 int bipbuf_is_empty(const bipbuf_t* me);
78 
79 /**
80  * @return how much space we have assigned */
81 int bipbuf_used(const bipbuf_t* cb);
82 
83 /**
84  * @return bytes of unused space */
85 int bipbuf_unused(const bipbuf_t* me);
86 
87 #endif /* BIPBUFFER_H */
88