don't oversend because of packet pairs

This commit is contained in:
Stephen Birarda 2016-03-23 18:07:28 -07:00
parent 57da7c2ba7
commit 1b322c8d01
2 changed files with 15 additions and 8 deletions

View file

@ -306,8 +306,10 @@ void SendQueue::run() {
// if we didn't find a packet to re-send AND we think we can fit a new packet on the wire
// (this is according to the current flow window size) then we send out a new packet
auto newPacketCount = 0;
if (!attemptedToSendPacket) {
attemptedToSendPacket = maybeSendNewPacket();
newPacketCount = maybeSendNewPacket();
attemptedToSendPacket = (newPacketCount > 0);
}
// since we're a while loop, give the thread a chance to process events
@ -322,7 +324,8 @@ void SendQueue::run() {
}
// push the next packet timestamp forwards by the current packet send period
nextPacketTimestamp += std::chrono::microseconds(_packetSendPeriod);
auto nextPacketDelta = (newPacketCount == 2 ? 2 : 1) * _packetSendPeriod;
nextPacketTimestamp += std::chrono::microseconds(nextPacketDelta);
// sleep as long as we need until next packet send, if we can
const auto timeToSleep = duration_cast<microseconds>(nextPacketTimestamp - p_high_resolution_clock::now());
@ -331,7 +334,7 @@ void SendQueue::run() {
}
}
bool SendQueue::maybeSendNewPacket() {
int SendQueue::maybeSendNewPacket() {
if (!isFlowWindowFull()) {
// we didn't re-send a packet, so time to send a new one
@ -366,14 +369,18 @@ bool SendQueue::maybeSendNewPacket() {
static auto pairTailPacket = ControlPacket::create(ControlPacket::ProbeTail);
_socket->writeBasePacket(*pairTailPacket, _destination);
}
}
// We attempted to send packet(s), return here
return true;
// we attempted to send two packets, return 2
return 2;
} else {
// we attempted to send a single packet, return 1
return 1;
}
}
}
// No packets were sent
return false;
return 0;
}
bool SendQueue::maybeResendPacket() {

View file

@ -95,7 +95,7 @@ private:
int sendPacket(const Packet& packet);
bool sendNewPacketAndAddToSentList(std::unique_ptr<Packet> newPacket, SequenceNumber sequenceNumber);
bool maybeSendNewPacket(); // Figures out what packet to send next
int maybeSendNewPacket(); // Figures out what packet to send next
bool maybeResendPacket(); // Determines whether to resend a packet and which one
bool isInactive(bool attemptedToSendPacket);