mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 16:55:07 +02:00
Merge pull request #7701 from birarda/udt-fixes
use nextPacketTimestamp to catch up, not stay ahead
This commit is contained in:
commit
92339bf5fc
1 changed files with 12 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue