From: Pierre Ossman Date: Thu, 29 Feb 2024 15:01:48 +0000 (+0100) Subject: Make it easier to change timer interval X-Git-Tag: v1.13.90~5^2~7 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=30bacaeadf83935c15f403e26e5e72f392f8c879;p=tigervnc.git Make it easier to change timer interval --- diff --git a/common/rfb/Timer.cxx b/common/rfb/Timer.cxx index 37aaad83..e9ae5227 100644 --- a/common/rfb/Timer.cxx +++ b/common/rfb/Timer.cxx @@ -122,7 +122,7 @@ void Timer::start(int timeoutMs_) { insertTimer(this); } -void Timer::repeat() { +void Timer::repeat(int timeoutMs_) { timeval now; gettimeofday(&now, 0); @@ -135,6 +135,9 @@ void Timer::repeat() { if (msBetween(&lastDueTime, &dueTime) != 0) vlog.error("Timer incorrectly modified whilst repeating"); + if (timeoutMs_ != -1) + timeoutMs = timeoutMs_; + dueTime = addMillis(lastDueTime, timeoutMs); if (isBefore(now)) { // Time has jumped forwards, or we're not getting enough diff --git a/common/rfb/Timer.h b/common/rfb/Timer.h index 9775afd5..36ec46c5 100644 --- a/common/rfb/Timer.h +++ b/common/rfb/Timer.h @@ -80,7 +80,9 @@ namespace rfb { // Restarts the timer in a way that repeats that last timeout. // This allows you to have a periodic timer without the risk of // accumulating drift caused by processing delays. - void repeat(); + // A new interval can be specified, otherwise the previous + // interval is reused. + void repeat(int timeoutMs_=-1); // stop() // Cancels the timer. diff --git a/common/rfb/VNCServerST.cxx b/common/rfb/VNCServerST.cxx index bd1fecf3..68379f24 100644 --- a/common/rfb/VNCServerST.cxx +++ b/common/rfb/VNCServerST.cxx @@ -633,10 +633,7 @@ void VNCServerST::handleTimeout(Timer* t) writeUpdate(); // If this is the first iteration then we need to adjust the timeout - if (frameTimer.getTimeoutMs() != 1000/rfb::Server::frameRate) - frameTimer.start(1000/rfb::Server::frameRate); - else - frameTimer.repeat(); + frameTimer.repeat(1000/rfb::Server::frameRate); } else if (t == &idleTimer) { slog.info("MaxIdleTime reached, exiting"); desktop->terminate();