1
0
mirror of https://github.com/facebookincubator/mvfst.git synced 2025-11-09 10:00:57 +03:00
Files
mvfst/quic/api/QuicPacketScheduler-inl.h
Subodh Iyengar 04baa15a04 Custom variant type for packetheader
Summary:
Make a custom variant type for PacketHeader. By not relying on boost::variant
this reduces the code size of the implementation.

This uses a combination of a union type as well as a enum type to emulate a variant

Reviewed By: yangchi

Differential Revision: D17187589

fbshipit-source-id: 00c2b9b8dd3f3e73af766d84888b13b9d867165a
2019-09-19 17:31:47 -07:00

69 lines
2.2 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.
*
*/
#include <quic/codec/QuicPacketRebuilder.h>
#include <quic/state/QuicStateFunctions.h>
#include <folly/lang/Assume.h>
namespace quic {
template <typename ClockType>
inline folly::Optional<PacketNum> AckScheduler::writeNextAcks(
PacketBuilderInterface& builder,
AckMode mode) {
switch (mode) {
case AckMode::Immediate: {
return writeAcksImpl<ClockType>(builder);
}
case AckMode::Pending: {
return writeAcksIfPending<ClockType>(builder);
}
}
folly::assume_unreachable();
}
template <typename ClockType>
inline folly::Optional<PacketNum> AckScheduler::writeAcksIfPending(
PacketBuilderInterface& builder) {
if (ackState_.needsToSendAckImmediately) {
return writeAcksImpl<ClockType>(builder);
}
return folly::none;
}
template <typename ClockType>
folly::Optional<PacketNum> AckScheduler::writeAcksImpl(
PacketBuilderInterface& builder) {
// Use default ack delay for long headers. Usually long headers are sent
// before crypto negotiation, so the peer might not know about the ack delay
// exponent yet, so we use the default.
uint8_t ackDelayExponentToUse =
builder.getPacketHeader().getHeaderForm() == HeaderForm::Long
? kDefaultAckDelayExponent
: conn_.transportSettings.ackDelayExponent;
auto largestAckedPacketNum = *largestAckToSend(ackState_);
auto ackingTime = ClockType::now();
DCHECK(ackState_.largestRecvdPacketTime.hasValue())
<< "Missing received time for the largest acked packet";
// assuming that we're going to ack the largest received with hightest pri
auto receivedTime = *ackState_.largestRecvdPacketTime;
std::chrono::microseconds ackDelay =
(ackingTime > receivedTime
? std::chrono::duration_cast<std::chrono::microseconds>(
ackingTime - receivedTime)
: 0us);
AckFrameMetaData meta(ackState_.acks, ackDelay, ackDelayExponentToUse);
auto ackWriteResult = writeAckFrame(meta, builder);
if (!ackWriteResult) {
return folly::none;
}
return largestAckedPacketNum;
}
} // namespace quic