123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412 |
- #ifndef NGHTTP2_BUF_H
- #define NGHTTP2_BUF_H
- #ifdef HAVE_CONFIG_H
- # include <config.h>
- #endif
- #include <nghttp2/nghttp2.h>
- #include "nghttp2_int.h"
- #include "nghttp2_mem.h"
- typedef struct {
-
- uint8_t *begin;
-
- uint8_t *end;
-
- uint8_t *pos;
-
- uint8_t *last;
-
- uint8_t *mark;
- } nghttp2_buf;
- #define nghttp2_buf_len(BUF) ((size_t)((BUF)->last - (BUF)->pos))
- #define nghttp2_buf_avail(BUF) ((size_t)((BUF)->end - (BUF)->last))
- #define nghttp2_buf_mark_avail(BUF) ((size_t)((BUF)->mark - (BUF)->last))
- #define nghttp2_buf_cap(BUF) ((size_t)((BUF)->end - (BUF)->begin))
- #define nghttp2_buf_pos_offset(BUF) ((size_t)((BUF)->pos - (BUF)->begin))
- #define nghttp2_buf_last_offset(BUF) ((size_t)((BUF)->last - (BUF)->begin))
- #define nghttp2_buf_shift_right(BUF, AMT) \
- do { \
- (BUF)->pos += AMT; \
- (BUF)->last += AMT; \
- } while (0)
- #define nghttp2_buf_shift_left(BUF, AMT) \
- do { \
- (BUF)->pos -= AMT; \
- (BUF)->last -= AMT; \
- } while (0)
- void nghttp2_buf_init(nghttp2_buf *buf);
- int nghttp2_buf_init2(nghttp2_buf *buf, size_t initial, nghttp2_mem *mem);
- void nghttp2_buf_free(nghttp2_buf *buf, nghttp2_mem *mem);
- int nghttp2_buf_reserve(nghttp2_buf *buf, size_t new_cap, nghttp2_mem *mem);
- void nghttp2_buf_reset(nghttp2_buf *buf);
- void nghttp2_buf_wrap_init(nghttp2_buf *buf, uint8_t *begin, size_t len);
- struct nghttp2_buf_chain;
- typedef struct nghttp2_buf_chain nghttp2_buf_chain;
- struct nghttp2_buf_chain {
-
- nghttp2_buf_chain *next;
- nghttp2_buf buf;
- };
- typedef struct {
-
- nghttp2_buf_chain *head;
-
- nghttp2_buf_chain *cur;
-
- nghttp2_mem *mem;
-
- size_t chunk_length;
-
- size_t max_chunk;
-
- size_t chunk_used;
-
- size_t chunk_keep;
-
- size_t offset;
- } nghttp2_bufs;
- int nghttp2_bufs_init(nghttp2_bufs *bufs, size_t chunk_length, size_t max_chunk,
- nghttp2_mem *mem);
- int nghttp2_bufs_init2(nghttp2_bufs *bufs, size_t chunk_length,
- size_t max_chunk, size_t offset, nghttp2_mem *mem);
- int nghttp2_bufs_init3(nghttp2_bufs *bufs, size_t chunk_length,
- size_t max_chunk, size_t chunk_keep, size_t offset,
- nghttp2_mem *mem);
- void nghttp2_bufs_free(nghttp2_bufs *bufs);
- int nghttp2_bufs_wrap_init(nghttp2_bufs *bufs, uint8_t *begin, size_t len,
- nghttp2_mem *mem);
- int nghttp2_bufs_wrap_init2(nghttp2_bufs *bufs, const nghttp2_vec *vec,
- size_t veclen, nghttp2_mem *mem);
- void nghttp2_bufs_wrap_free(nghttp2_bufs *bufs);
- int nghttp2_bufs_realloc(nghttp2_bufs *bufs, size_t chunk_length);
- int nghttp2_bufs_add(nghttp2_bufs *bufs, const void *data, size_t len);
- int nghttp2_bufs_addb(nghttp2_bufs *bufs, uint8_t b);
- int nghttp2_bufs_addb_hold(nghttp2_bufs *bufs, uint8_t b);
- #define nghttp2_bufs_fast_addb(BUFS, B) \
- do { \
- *(BUFS)->cur->buf.last++ = B; \
- } while (0)
- #define nghttp2_bufs_fast_addb_hold(BUFS, B) \
- do { \
- *(BUFS)->cur->buf.last = B; \
- } while (0)
- int nghttp2_bufs_orb(nghttp2_bufs *bufs, uint8_t b);
- int nghttp2_bufs_orb_hold(nghttp2_bufs *bufs, uint8_t b);
- #define nghttp2_bufs_fast_orb(BUFS, B) \
- do { \
- uint8_t **p = &(BUFS)->cur->buf.last; \
- **p = (uint8_t)(**p | (B)); \
- ++(*p); \
- } while (0)
- #define nghttp2_bufs_fast_orb_hold(BUFS, B) \
- do { \
- uint8_t *p = (BUFS)->cur->buf.last; \
- *p = (uint8_t)(*p | (B)); \
- } while (0)
- ssize_t nghttp2_bufs_remove(nghttp2_bufs *bufs, uint8_t **out);
- size_t nghttp2_bufs_remove_copy(nghttp2_bufs *bufs, uint8_t *out);
- void nghttp2_bufs_reset(nghttp2_bufs *bufs);
- int nghttp2_bufs_advance(nghttp2_bufs *bufs);
- #define nghttp2_bufs_rewind(BUFS) \
- do { \
- (BUFS)->cur = (BUFS)->head; \
- } while (0)
- void nghttp2_bufs_seek_last_present(nghttp2_bufs *bufs);
- int nghttp2_bufs_next_present(nghttp2_bufs *bufs);
- #define nghttp2_bufs_cur_avail(BUFS) nghttp2_buf_avail(&(BUFS)->cur->buf)
- size_t nghttp2_bufs_len(nghttp2_bufs *bufs);
- #endif
|