2022-05-09 03:37:27 -04:00
|
|
|
#ifndef _HAPROXY_NCBUF_H
|
|
|
|
|
#define _HAPROXY_NCBUF_H
|
|
|
|
|
|
|
|
|
|
#include <haproxy/ncbuf-t.h>
|
|
|
|
|
|
2022-11-28 09:08:14 -05:00
|
|
|
static inline int ncb_is_null(const struct ncbuf *buf)
|
|
|
|
|
{
|
|
|
|
|
return buf->size == 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-09 03:37:27 -04:00
|
|
|
void ncb_init(struct ncbuf *buf, ncb_sz_t head);
|
|
|
|
|
struct ncbuf ncb_make(char *area, ncb_sz_t size, ncb_sz_t head);
|
|
|
|
|
|
2022-11-28 09:08:14 -05:00
|
|
|
/* 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;
|
|
|
|
|
}
|
2022-05-09 03:37:27 -04:00
|
|
|
|
2022-05-09 03:38:45 -04:00
|
|
|
ncb_sz_t ncb_total_data(const struct ncbuf *buf);
|
2022-05-09 03:37:27 -04:00
|
|
|
int ncb_is_empty(const struct ncbuf *buf);
|
|
|
|
|
int ncb_is_full(const struct ncbuf *buf);
|
2022-07-01 08:45:41 -04:00
|
|
|
int ncb_is_fragmented(const struct ncbuf *buf);
|
2022-05-09 03:37:27 -04:00
|
|
|
|
2022-05-09 03:38:45 -04:00
|
|
|
ncb_sz_t ncb_data(const struct ncbuf *buf, ncb_sz_t offset);
|
|
|
|
|
|
2022-05-09 03:43:11 -04:00
|
|
|
enum ncb_ret ncb_add(struct ncbuf *buf, ncb_sz_t off,
|
2022-05-09 05:59:15 -04:00
|
|
|
const char *data, ncb_sz_t len, enum ncb_add_mode mode);
|
2022-05-17 12:52:39 -04:00
|
|
|
enum ncb_ret ncb_advance(struct ncbuf *buf, ncb_sz_t adv);
|
2022-05-09 03:43:11 -04:00
|
|
|
|
2022-05-09 03:37:27 -04:00
|
|
|
#endif /* _HAPROXY_NCBUF_H */
|