lsquic_frab_list.h revision 5392f7a3
15392f7a3SLiteSpeed Tech/* Copyright (c) 2017 - 2019 LiteSpeed Technologies Inc. See LICENSE. */ 25392f7a3SLiteSpeed Tech/* 35392f7a3SLiteSpeed Tech * lsquic_frab_list.h -- List of buffer for simple reading and writing 45392f7a3SLiteSpeed Tech * 55392f7a3SLiteSpeed Tech * Useful for buffering data that cannot be packetized immediately. 65392f7a3SLiteSpeed Tech */ 75392f7a3SLiteSpeed Tech 85392f7a3SLiteSpeed Tech#ifndef LSQUIC_FRAB_LIST_H 95392f7a3SLiteSpeed Tech#define LSQUIC_FRAB_LIST_H 1 105392f7a3SLiteSpeed Tech 115392f7a3SLiteSpeed Techstruct frame_buf 125392f7a3SLiteSpeed Tech{ 135392f7a3SLiteSpeed Tech TAILQ_ENTRY(frame_buf) frab_next; 145392f7a3SLiteSpeed Tech unsigned short frab_size, 155392f7a3SLiteSpeed Tech frab_off, 165392f7a3SLiteSpeed Tech frab_buf_size; /* Total bytes in frab_buf */ 175392f7a3SLiteSpeed Tech unsigned char frab_buf[0]; 185392f7a3SLiteSpeed Tech}; 195392f7a3SLiteSpeed Tech 205392f7a3SLiteSpeed Tech#define frab_left_to_read(f) ((f)->frab_size - (f)->frab_off) 215392f7a3SLiteSpeed Tech#define frab_left_to_write(f) ((f)->frab_buf_size - \ 225392f7a3SLiteSpeed Tech (unsigned short) sizeof(*(f)) - (f)->frab_size) 235392f7a3SLiteSpeed Tech#define frab_write_to(f) ((f)->frab_buf + (f)->frab_size) 245392f7a3SLiteSpeed Tech 255392f7a3SLiteSpeed TechTAILQ_HEAD(frame_buf_head, frame_buf); 265392f7a3SLiteSpeed Tech 275392f7a3SLiteSpeed Techstruct frab_list 285392f7a3SLiteSpeed Tech{ 295392f7a3SLiteSpeed Tech struct frame_buf_head fl_frabs; 305392f7a3SLiteSpeed Tech void * (*fl_alloc)(void *alloc_ctx, size_t size); 315392f7a3SLiteSpeed Tech void (*fl_free)(void *alloc_ctx, void *obj); 325392f7a3SLiteSpeed Tech void *fl_alloc_ctx; 335392f7a3SLiteSpeed Tech size_t fl_size; /* Size of payload in frab_list */ 345392f7a3SLiteSpeed Tech unsigned short fl_buf_size; /* Size of frame_buf */ 355392f7a3SLiteSpeed Tech}; 365392f7a3SLiteSpeed Tech 375392f7a3SLiteSpeed Techvoid 385392f7a3SLiteSpeed Techlsquic_frab_list_init (struct frab_list *, unsigned short buf_size, 395392f7a3SLiteSpeed Tech void * (*fl_alloc)(void *alloc_ctx, size_t size), 405392f7a3SLiteSpeed Tech void (*fl_free)(void *alloc_ctx, void *obj), void *fl_alloc_ctx); 415392f7a3SLiteSpeed Tech 425392f7a3SLiteSpeed Techvoid 435392f7a3SLiteSpeed Techlsquic_frab_list_cleanup (struct frab_list *); 445392f7a3SLiteSpeed Tech 455392f7a3SLiteSpeed Techint 465392f7a3SLiteSpeed Techlsquic_frab_list_write (struct frab_list *, const void *, size_t); 475392f7a3SLiteSpeed Tech 485392f7a3SLiteSpeed Techsize_t 495392f7a3SLiteSpeed Techlsquic_frab_list_size (void *); 505392f7a3SLiteSpeed Tech 515392f7a3SLiteSpeed Techsize_t 525392f7a3SLiteSpeed Techlsquic_frab_list_read (void *, void *, size_t); 535392f7a3SLiteSpeed Tech 545392f7a3SLiteSpeed Tech#define lsquic_frab_list_empty(fral) TAILQ_EMPTY(&(fral)->fl_frabs) 555392f7a3SLiteSpeed Tech 565392f7a3SLiteSpeed Techsize_t 575392f7a3SLiteSpeed Techlsquic_frab_list_mem_used (const struct frab_list *); 585392f7a3SLiteSpeed Tech 595392f7a3SLiteSpeed Tech#endif 60