From b53c3bf050d4ea7693f53be01b5d3ea85055c01d Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 22 Mar 2018 16:01:44 +0100 Subject: [PATCH] Avoid checking updates when desktop is stopped No need to run all the update machinery when there is no client connected. This commit also cleans up the stop handling a bit by moving it to its own method. --- common/rfb/VNCServerST.cxx | 28 +++++++++++++++++----------- common/rfb/VNCServerST.h | 1 + 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/common/rfb/VNCServerST.cxx b/common/rfb/VNCServerST.cxx index 0008dc41..83f2b7e7 100644 --- a/common/rfb/VNCServerST.cxx +++ b/common/rfb/VNCServerST.cxx @@ -1,5 +1,5 @@ /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. - * Copyright 2009-2017 Pierre Ossman for Cendio AB + * Copyright 2009-2018 Pierre Ossman for Cendio AB * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -105,10 +105,7 @@ VNCServerST::~VNCServerST() } // Stop the desktop object if active, *only* after deleting all clients! - if (desktopStarted) { - desktopStarted = false; - desktop->stop(); - } + stopDesktop(); if (comparer) comparer->logStats(); @@ -154,12 +151,8 @@ void VNCServerST::removeSocket(network::Socket* sock) { delete *ci; // - Check that the desktop object is still required - if (authClientCount() == 0 && desktopStarted) { - slog.debug("no authenticated clients - stopping desktop"); - desktopStarted = false; - desktop->stop(); - stopFrameClock(); - } + if (authClientCount() == 0) + stopDesktop(); if (comparer) comparer->logStats(); @@ -552,6 +545,16 @@ void VNCServerST::startDesktop() } } +void VNCServerST::stopDesktop() +{ + if (desktopStarted) { + slog.debug("stopping desktop"); + desktopStarted = false; + desktop->stop(); + stopFrameClock(); + } +} + int VNCServerST::authClientCount() { int count = 0; std::list::iterator ci; @@ -576,6 +579,8 @@ void VNCServerST::startFrameClock() return; if (blockCounter > 0) return; + if (!desktopStarted) + return; // The first iteration will be just half a frame as we get a very // unstable update rate if we happen to be perfectly in sync with @@ -603,6 +608,7 @@ void VNCServerST::writeUpdate() std::list::iterator ci, ci_next; assert(blockCounter == 0); + assert(desktopStarted); comparer->getUpdateInfo(&ui, pb->getRect()); toCheck = ui.changed.union_(ui.copied); diff --git a/common/rfb/VNCServerST.h b/common/rfb/VNCServerST.h index e00a1f7e..584c48c2 100644 --- a/common/rfb/VNCServerST.h +++ b/common/rfb/VNCServerST.h @@ -195,6 +195,7 @@ namespace rfb { // - Internal methods void startDesktop(); + void stopDesktop(); static LogWriter connectionsLog; Blacklist blacklist; -- 2.39.5