/* ex: set ff=dos ts=2 et: */ /* $Id$ */ /* * Copyright 2008 Ryan Flynn * All rights reserved. */ /* * standard interface for reading, passing and consuming network data */ #ifndef BUF_H #define BUF_H #include /* size_t */ #include "types.h" typedef struct { size_t buflen, /* how much data is in */ start, /* where the start of the current data is */ len; /* how much more data has been received than processed */ u8 *data; } buf; void buf_init (buf *, u8*, size_t); size_t buf_after (const buf *, const u8 *); size_t buf_append (buf *, const u8 *, size_t); size_t buf_append_circ (buf *, const u8 *, size_t); size_t buf_data_contig (buf *); size_t buf_space_contig(buf *); void buf_consume (buf *, size_t); void buf_lengthen (buf *, size_t); void buf_shift (buf *); void buf_clr (buf *); #define buf_start(b) ((b)->data + (b)->start) #define buf_end(b) (buf_start(b) + (b)->len) #define buf_space(b) ((size_t)((b)->buflen - ((b)->start + (b)->len))) /* space left */ #define buf_len(b) ((b)->len) /* amount of contiguous data after start (for buf which may be circular) */ #define buf_buflen(b) ((b)->buflen) #endif