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