summaryrefslogtreecommitdiffstats
path: root/include/haproxy/ncbuf.h
blob: 8972793d9502348db656b73285ccdce3087ac5d8 (plain)
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
#ifndef _HAPROXY_NCBUF_H
#define _HAPROXY_NCBUF_H

#include <haproxy/ncbuf-t.h>

static inline int ncb_is_null(const struct ncbuf *buf)
{
	return buf->size == 0;
}

void ncb_init(struct ncbuf *buf, ncb_sz_t head);
struct ncbuf ncb_make(char *area, ncb_sz_t size, ncb_sz_t head);

/* Returns start of allocated buffer area. */
static inline char *ncb_orig(const struct ncbuf *buf)
{
	return buf->area;
}

/* Returns current head pointer into buffer area. */
static inline char *ncb_head(const struct ncbuf *buf)
{
	return buf->area + buf->head;
}

/* Returns the first byte after the allocated buffer area. */
static inline char *ncb_wrap(const struct ncbuf *buf)
{
	return buf->area + buf->size;
}

/* Returns the usable size of <buf> for data storage. This is the size of the
 * allocated buffer without the reserved header space.
 */
static inline ncb_sz_t ncb_size(const struct ncbuf *buf)
{
	if (ncb_is_null(buf))
		return 0;

	return buf->size - NCB_RESERVED_SZ;
}

ncb_sz_t ncb_total_data(const struct ncbuf *buf);
int ncb_is_empty(const struct ncbuf *buf);
int ncb_is_full(const struct ncbuf *buf);
int ncb_is_fragmented(const struct ncbuf *buf);

ncb_sz_t ncb_data(const struct ncbuf *buf, ncb_sz_t offset);

enum ncb_ret ncb_add(struct ncbuf *buf, ncb_sz_t off,
                     const char *data, ncb_sz_t len, enum ncb_add_mode mode);
enum ncb_ret ncb_advance(struct ncbuf *buf, ncb_sz_t adv);

#endif /* _HAPROXY_NCBUF_H */