lsquic_frab_list.h revision 5392f7a3
1/* Copyright (c) 2017 - 2019 LiteSpeed Technologies Inc. See LICENSE. */ 2/* 3 * lsquic_frab_list.h -- List of buffer for simple reading and writing 4 * 5 * Useful for buffering data that cannot be packetized immediately. 6 */ 7 8#ifndef LSQUIC_FRAB_LIST_H 9#define LSQUIC_FRAB_LIST_H 1 10 11struct frame_buf 12{ 13 TAILQ_ENTRY(frame_buf) frab_next; 14 unsigned short frab_size, 15 frab_off, 16 frab_buf_size; /* Total bytes in frab_buf */ 17 unsigned char frab_buf[0]; 18}; 19 20#define frab_left_to_read(f) ((f)->frab_size - (f)->frab_off) 21#define frab_left_to_write(f) ((f)->frab_buf_size - \ 22 (unsigned short) sizeof(*(f)) - (f)->frab_size) 23#define frab_write_to(f) ((f)->frab_buf + (f)->frab_size) 24 25TAILQ_HEAD(frame_buf_head, frame_buf); 26 27struct frab_list 28{ 29 struct frame_buf_head fl_frabs; 30 void * (*fl_alloc)(void *alloc_ctx, size_t size); 31 void (*fl_free)(void *alloc_ctx, void *obj); 32 void *fl_alloc_ctx; 33 size_t fl_size; /* Size of payload in frab_list */ 34 unsigned short fl_buf_size; /* Size of frame_buf */ 35}; 36 37void 38lsquic_frab_list_init (struct frab_list *, unsigned short buf_size, 39 void * (*fl_alloc)(void *alloc_ctx, size_t size), 40 void (*fl_free)(void *alloc_ctx, void *obj), void *fl_alloc_ctx); 41 42void 43lsquic_frab_list_cleanup (struct frab_list *); 44 45int 46lsquic_frab_list_write (struct frab_list *, const void *, size_t); 47 48size_t 49lsquic_frab_list_size (void *); 50 51size_t 52lsquic_frab_list_read (void *, void *, size_t); 53 54#define lsquic_frab_list_empty(fral) TAILQ_EMPTY(&(fral)->fl_frabs) 55 56size_t 57lsquic_frab_list_mem_used (const struct frab_list *); 58 59#endif 60