From bf286837db638a67bde0ab9be0baa621f863b8d5 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 3 Jan 2023 09:24:51 +0100 Subject: Stop treating "0" as "no timeouts" It is much more sane to treat "0" as "a timer is ready NOW", so let's change to using -1 as the invalid timeout value. --- unix/vncconfig/vncconfig.cxx | 2 +- unix/x0vncserver/x0vncserver.cxx | 7 +++++-- unix/xserver/hw/vnc/XserverDesktop.cc | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) (limited to 'unix') diff --git a/unix/vncconfig/vncconfig.cxx b/unix/vncconfig/vncconfig.cxx index f39e9934..be8c8195 100644 --- a/unix/vncconfig/vncconfig.cxx +++ b/unix/vncconfig/vncconfig.cxx @@ -308,7 +308,7 @@ int main(int argc, char** argv) // Process expired timers and get the time until the next one int timeoutMs = Timer::checkTimeouts(); - if (timeoutMs) { + if (timeoutMs >= 0) { tv.tv_sec = timeoutMs / 1000; tv.tv_usec = (timeoutMs % 1000) * 1000; tvp = &tv; diff --git a/unix/x0vncserver/x0vncserver.cxx b/unix/x0vncserver/x0vncserver.cxx index 8e27e62b..ffaf5788 100644 --- a/unix/x0vncserver/x0vncserver.cxx +++ b/unix/x0vncserver/x0vncserver.cxx @@ -382,7 +382,7 @@ int main(int argc, char** argv) PollingScheduler sched((int)pollingCycle, (int)maxProcessorUsage); while (!caughtSignal) { - int wait_ms; + int wait_ms, nextTimeout; struct timeval tv; fd_set rfds, wfds; std::list sockets; @@ -426,7 +426,10 @@ int main(int argc, char** argv) } } - soonestTimeout(&wait_ms, Timer::checkTimeouts()); + // Trigger timers and check when the next will expire + nextTimeout = Timer::checkTimeouts(); + if (nextTimeout >= 0 && nextTimeout < wait_ms) + wait_ms = nextTimeout; tv.tv_sec = wait_ms / 1000; tv.tv_usec = (wait_ms % 1000) * 1000; diff --git a/unix/xserver/hw/vnc/XserverDesktop.cc b/unix/xserver/hw/vnc/XserverDesktop.cc index b5a58671..64b2e614 100644 --- a/unix/xserver/hw/vnc/XserverDesktop.cc +++ b/unix/xserver/hw/vnc/XserverDesktop.cc @@ -395,7 +395,7 @@ void XserverDesktop::blockHandler(int* timeout) // Trigger timers and check when the next will expire int nextTimeout = Timer::checkTimeouts(); - if (nextTimeout > 0 && (*timeout == -1 || nextTimeout < *timeout)) + if (nextTimeout >= 0 && (*timeout == -1 || nextTimeout < *timeout)) *timeout = nextTimeout; } catch (rdr::Exception& e) { vlog.error("XserverDesktop::blockHandler: %s",e.str()); -- cgit v1.2.3