Set minimum timeout for retransmits

This commit is contained in:
Simon Walton 2018-12-17 14:07:21 -08:00
parent 719919d3fd
commit 0d14e0bcf7
2 changed files with 8 additions and 6 deletions

View file

@ -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> 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);

View file

@ -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;
};
}