From 0d14e0bcf7be99a345347bbd95c5da2e708b9f5a Mon Sep 17 00:00:00 2001 From: Simon Walton Date: Mon, 17 Dec 2018 14:07:21 -0800 Subject: [PATCH] Set minimum timeout for retransmits --- libraries/networking/src/udt/SendQueue.cpp | 11 +++++------ libraries/networking/src/udt/SendQueue.h | 3 +++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/libraries/networking/src/udt/SendQueue.cpp b/libraries/networking/src/udt/SendQueue.cpp index 3178217a36..262b62de12 100644 --- a/libraries/networking/src/udt/SendQueue.cpp +++ b/libraries/networking/src/udt/SendQueue.cpp @@ -61,6 +61,9 @@ private: Mutex2& _mutex2; }; +const microseconds SendQueue::MAXIMUM_ESTIMATED_TIMEOUT = seconds(5); +const microseconds SendQueue::MINIMUM_ESTIMATED_TIMEOUT = milliseconds(10); + std::unique_ptr SendQueue::create(Socket* socket, HifiSockAddr destination, SequenceNumber currentSequenceNumber, MessageNumber currentMessageNumber, bool hasReceivedHandshakeACK) { Q_ASSERT_X(socket, "SendQueue::create", "Must be called with a valid Socket*"); @@ -505,12 +508,8 @@ bool SendQueue::isInactive(bool attemptedToSendPacket) { auto estimatedTimeout = std::chrono::microseconds(_estimatedTimeout); - // cap our maximum estimated timeout to the already unreasonable 5 seconds - const auto MAXIMUM_ESTIMATED_TIMEOUT = std::chrono::seconds(5); - - if (estimatedTimeout > MAXIMUM_ESTIMATED_TIMEOUT) { - estimatedTimeout = MAXIMUM_ESTIMATED_TIMEOUT; - } + // Clamp timeout beween 10 ms and 5 s + estimatedTimeout = std::min(MAXIMUM_ESTIMATED_TIMEOUT, std::max(MINIMUM_ESTIMATED_TIMEOUT, estimatedTimeout)); // use our condition_variable_any to wait auto cvStatus = _emptyCondition.wait_for(locker, estimatedTimeout); diff --git a/libraries/networking/src/udt/SendQueue.h b/libraries/networking/src/udt/SendQueue.h index c1faac3b22..e5c0e370c4 100644 --- a/libraries/networking/src/udt/SendQueue.h +++ b/libraries/networking/src/udt/SendQueue.h @@ -140,6 +140,9 @@ private: std::condition_variable_any _emptyCondition; std::chrono::high_resolution_clock::time_point _lastPacketSentAt; + + static const std::chrono::microseconds MAXIMUM_ESTIMATED_TIMEOUT; + static const std::chrono::microseconds MINIMUM_ESTIMATED_TIMEOUT; }; }