lsquic_senhist.h revision 229fce07
1/* Copyright (c) 2017 - 2019 LiteSpeed Technologies Inc. See LICENSE. */ 2/* 3 * lsquic_senhist.h -- History sent packets. 4 * 5 * We need to keep track of packet numbers in order to verify ACKs. To 6 * speed up processing, we make sure that there is never a gap in the 7 * packet number sequence we generate. 8 */ 9 10#ifndef LSQUIC_SENHIST_H 11#define LSQUIC_SENHIST_H 1 12 13#ifndef LSQUIC_SENHIST_FATAL 14# define LSQUIC_SENHIST_FATAL 0 15#endif 16 17typedef struct lsquic_senhist { 18 lsquic_packno_t sh_last_sent; 19#if !LSQUIC_SENHIST_FATAL 20 enum { 21 SH_WARNED = 1 << 0, /* Warn once */ 22 } sh_flags; 23#endif 24} lsquic_senhist_t; 25 26#define lsquic_senhist_init(hist) do { \ 27 (hist)->sh_last_sent = 0; \ 28} while (0) 29 30#define lsquic_senhist_cleanup(hist) 31 32#if LSQUIC_SENHIST_FATAL 33#define lsquic_senhist_add(hist, packno) do { \ 34 assert((hist)->sh_last_sent == packno - 1); \ 35 (hist)->sh_last_sent = packno; \ 36} while (0) 37#else 38#define lsquic_senhist_add(hist, packno) do { \ 39 if ((hist)->sh_last_sent == packno - 1) \ 40 (hist)->sh_last_sent = packno; \ 41 else \ 42 { \ 43 if (!((hist)->sh_flags & SH_WARNED)) \ 44 { \ 45 LSQ_WARN("send history gap %"PRIu64" - %"PRIu64, \ 46 (hist)->sh_last_sent, packno); \ 47 (hist)->sh_flags |= SH_WARNED; \ 48 } \ 49 (hist)->sh_last_sent = packno; \ 50 } \ 51} while (0) 52#endif 53 54/* Returns 0 if no packets have been sent yet */ 55#define lsquic_senhist_largest(hist) (+(hist)->sh_last_sent) 56 57void 58lsquic_senhist_tostr (lsquic_senhist_t *hist, char *buf, size_t bufsz); 59 60#define lsquic_senhist_mem_used(hist) (sizeof(*(hist))) 61 62#endif 63