Merge pull request #7701 from birarda/udt-fixes

use nextPacketTimestamp to catch up, not stay ahead
This commit is contained in:
Ryan Huffman 2016-04-19 12:57:43 -07:00
commit 92339bf5fc

View file

@ -329,10 +329,21 @@ void SendQueue::run() {
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
// sleep as long as we need for next packet send, if we can
auto now = p_high_resolution_clock::now();
auto timeToSleep = duration_cast<microseconds>(nextPacketTimestamp - now);
// we use nextPacketTimestamp so that we don't fall behind, not to force long sleeps
// we'll never allow nextPacketTimestamp to force us to sleep for more than nextPacketDelta
// so cap it to that value
if (timeToSleep > std::chrono::microseconds(nextPacketDelta)) {
// reset the nextPacketTimestamp so that it is correct next time we come around
nextPacketTimestamp = now + std::chrono::microseconds(nextPacketDelta);
timeToSleep = std::chrono::microseconds(nextPacketDelta);
}
// we're seeing SendQueues sleep for a long period of time here,
// which can lock the NodeList if it's attempting to clear connections
// for now we guard this by capping the time this thread and sleep for