From 1b322c8d015fd59a657e71c4aa88b4949c5df0f1 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 23 Mar 2016 18:07:28 -0700 Subject: [PATCH] don't oversend because of packet pairs --- libraries/networking/src/udt/SendQueue.cpp | 21 ++++++++++++++------- libraries/networking/src/udt/SendQueue.h | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/libraries/networking/src/udt/SendQueue.cpp b/libraries/networking/src/udt/SendQueue.cpp index 2c3303537c..30c9f2f491 100644 --- a/libraries/networking/src/udt/SendQueue.cpp +++ b/libraries/networking/src/udt/SendQueue.cpp @@ -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(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() { diff --git a/libraries/networking/src/udt/SendQueue.h b/libraries/networking/src/udt/SendQueue.h index dc151e9f4d..77c7f3e85e 100644 --- a/libraries/networking/src/udt/SendQueue.h +++ b/libraries/networking/src/udt/SendQueue.h @@ -95,7 +95,7 @@ private: int sendPacket(const Packet& packet); bool sendNewPacketAndAddToSentList(std::unique_ptr 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);