From 278e420bbb855f39b67e21e583bea599ea8b020a Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Fri, 29 Apr 2016 14:28:54 +0200 Subject: [PATCH] Fix timeout handling in x0vncserver We need to proper respect the timeouts set up by the core RFB code and not just the polling scheduler. --- unix/x0vncserver/x0vncserver.cxx | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/unix/x0vncserver/x0vncserver.cxx b/unix/x0vncserver/x0vncserver.cxx index 791714e9..caf7814f 100644 --- a/unix/x0vncserver/x0vncserver.cxx +++ b/unix/x0vncserver/x0vncserver.cxx @@ -508,6 +508,7 @@ int main(int argc, char** argv) PollingScheduler sched((int)pollingCycle, (int)maxProcessorUsage); while (!caughtSignal) { + int wait_ms; struct timeval tv; fd_set rfds; std::list sockets; @@ -538,23 +539,24 @@ int main(int argc, char** argv) if (!clients_connected) sched.reset(); + wait_ms = 0; + if (sched.isRunning()) { - int wait_ms = sched.millisRemaining(); + wait_ms = sched.millisRemaining(); if (wait_ms > 500) { wait_ms = 500; } - tv.tv_usec = wait_ms * 1000; -#ifdef DEBUG - // fprintf(stderr, "[%d]\t", wait_ms); -#endif - } else { - tv.tv_usec = 100000; } - tv.tv_sec = 0; + + soonestTimeout(&wait_ms, server.checkTimeouts()); + + tv.tv_sec = wait_ms / 1000; + tv.tv_usec = (wait_ms % 1000) * 1000; // Do the wait... sched.sleepStarted(); - int n = select(FD_SETSIZE, &rfds, 0, 0, &tv); + int n = select(FD_SETSIZE, &rfds, 0, 0, + wait_ms ? &tv : NULL); sched.sleepFinished(); if (n < 0) { @@ -580,7 +582,6 @@ int main(int argc, char** argv) } } - Timer::checkTimeouts(); server.checkTimeouts(); // Client list could have been changed. -- 2.39.5