lsquic_senhist.h revision 16a9b66a
150aadb33SDmitri Tikhonov/* Copyright (c) 2017 LiteSpeed Technologies Inc.  See LICENSE. */
250aadb33SDmitri Tikhonov/*
350aadb33SDmitri Tikhonov * lsquic_senhist.h -- History sent packets.
450aadb33SDmitri Tikhonov *
516a9b66aSDmitri Tikhonov * We need to keep track of packet numbers in order to verify ACKs.  To
616a9b66aSDmitri Tikhonov * speed up processing, we make sure that there is never a gap in the
716a9b66aSDmitri Tikhonov * packet number sequence we generate.
850aadb33SDmitri Tikhonov */
950aadb33SDmitri Tikhonov
1050aadb33SDmitri Tikhonov#ifndef LSQUIC_SENHIST_H
1150aadb33SDmitri Tikhonov#define LSQUIC_SENHIST_H 1
1250aadb33SDmitri Tikhonov
1316a9b66aSDmitri Tikhonov#ifndef LSQUIC_SENHIST_FATAL
1416a9b66aSDmitri Tikhonov#   define LSQUIC_SENHIST_FATAL 0
1516a9b66aSDmitri Tikhonov#endif
1650aadb33SDmitri Tikhonov
1750aadb33SDmitri Tikhonovtypedef struct lsquic_senhist {
1816a9b66aSDmitri Tikhonov    lsquic_packno_t             sh_last_sent;
1916a9b66aSDmitri Tikhonov#if !LSQUIC_SENHIST_FATAL
2016a9b66aSDmitri Tikhonov    enum {
2116a9b66aSDmitri Tikhonov        SH_WARNED   = 1 << 0,   /* Warn once */
2216a9b66aSDmitri Tikhonov    }                           sh_flags;
2316a9b66aSDmitri Tikhonov#endif
2450aadb33SDmitri Tikhonov} lsquic_senhist_t;
2550aadb33SDmitri Tikhonov
2616a9b66aSDmitri Tikhonov#define lsquic_senhist_init(hist) do {                                  \
2716a9b66aSDmitri Tikhonov    (hist)->sh_last_sent = 0;                                           \
2816a9b66aSDmitri Tikhonov} while (0)
2916a9b66aSDmitri Tikhonov
3016a9b66aSDmitri Tikhonov#define lsquic_senhist_cleanup(hist)
3116a9b66aSDmitri Tikhonov
3216a9b66aSDmitri Tikhonov#if LSQUIC_SENHIST_FATAL
3316a9b66aSDmitri Tikhonov#define lsquic_senhist_add(hist, packno) do {                           \
3416a9b66aSDmitri Tikhonov    assert((hist)->sh_last_sent == packno - 1);                         \
3516a9b66aSDmitri Tikhonov    (hist)->sh_last_sent = packno;                                      \
3616a9b66aSDmitri Tikhonov} while (0)
3716a9b66aSDmitri Tikhonov#else
3816a9b66aSDmitri Tikhonov#define lsquic_senhist_add(hist, packno) do {                           \
3916a9b66aSDmitri Tikhonov    if ((hist)->sh_last_sent == packno - 1)                             \
4016a9b66aSDmitri Tikhonov        (hist)->sh_last_sent = packno;                                  \
4116a9b66aSDmitri Tikhonov    else                                                                \
4216a9b66aSDmitri Tikhonov    {                                                                   \
4316a9b66aSDmitri Tikhonov        if (!((hist)->sh_flags & SH_WARNED))                            \
4416a9b66aSDmitri Tikhonov        {                                                               \
4516a9b66aSDmitri Tikhonov            LSQ_WARN("send history gap %"PRIu64" - %"PRIu64,            \
4616a9b66aSDmitri Tikhonov                (hist)->sh_last_sent, packno);                          \
4716a9b66aSDmitri Tikhonov            (hist)->sh_flags |= SH_WARNED;                              \
4816a9b66aSDmitri Tikhonov        }                                                               \
4916a9b66aSDmitri Tikhonov        (hist)->sh_last_sent = packno;                                  \
5016a9b66aSDmitri Tikhonov    }                                                                   \
5116a9b66aSDmitri Tikhonov} while (0)
5216a9b66aSDmitri Tikhonov#endif
5350aadb33SDmitri Tikhonov
5450aadb33SDmitri Tikhonov/* Returns 0 if no packets have been sent yet */
5516a9b66aSDmitri Tikhonov#define lsquic_senhist_largest(hist) (+(hist)->sh_last_sent)
5650aadb33SDmitri Tikhonov
5750aadb33SDmitri Tikhonovvoid
5850aadb33SDmitri Tikhonovlsquic_senhist_tostr (lsquic_senhist_t *hist, char *buf, size_t bufsz);
5950aadb33SDmitri Tikhonov
6016a9b66aSDmitri Tikhonov#define lsquic_senhist_mem_used(hist) (sizeof(*(hist)))
61c51ce338SDmitri Tikhonov
6250aadb33SDmitri Tikhonov#endif
63