1
0
mirror of https://github.com/facebookincubator/mvfst.git synced 2025-11-25 15:43:13 +03:00
Files
mvfst/quic/common/EnumArray.h
Andrejs Krasilnikovs 8114c3e3d0 Changed last packet sent times to bet per-packet-number-space andthe PTO timer calculation from them
Summary:
This diff:
1) introduces `EnumArray` - effectively an `std::array` indexed by an enum
2) changes loss times and `lastRetransmittablePacketSentTime` inside `LossState`  to be an `EnumArray` indexed by `PacketNumberSpace`
3) makes the method `isHandshakeDone()` available for both client and server handshakes.
4) uses all those inputs to determine PTO timers in `earliestTimeAndSpace()`

Reviewed By: yangchi

Differential Revision: D19650864

fbshipit-source-id: d72e4a0cf61d2dcb76f0a7f4037c36a7c8156942
2020-02-10 12:28:43 -08:00

54 lines
1.5 KiB
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
#pragma once
#include <array>
#include <utility>
namespace quic {
// A generic class that extends std::array to be indexable using an Enum.
// The enum K has to list enumerators with all values between 0 and K::MAX
// (inclusive) and no others
template <class K, class V>
class EnumArray : public std::array<V, size_t(K::MAX) + 1> {
public:
using IntType = typename std::underlying_type<K>::type;
static constexpr IntType ArraySize = IntType(K::MAX) + 1;
constexpr const V& operator[](K key) const {
size_t ik = keyToInt(key);
return this->std::array<V, size_t(K::MAX) + 1>::operator[](ik);
}
constexpr V& operator[](K key) {
size_t ik = keyToInt(key);
return this->std::array<V, size_t(K::MAX) + 1>::operator[](ik);
}
// Returns all valid values for the enum
[[nodiscard]] constexpr std::array<K, ArraySize> keys() const {
return keyArrayHelper(std::make_integer_sequence<IntType, ArraySize>{});
}
private:
constexpr IntType keyToInt(K key) const {
auto ik = static_cast<IntType>(key);
DCHECK(ik >= 0 && ik < ArraySize);
return ik;
}
template <IntType... i>
constexpr auto keyArrayHelper(std::integer_sequence<IntType, i...>) const {
return std::array<K, sizeof...(i)>{static_cast<K>(i)...};
}
std::array<V, ArraySize> arr;
};
} // namespace quic