From 2804ea1b714c44ae6f4066baf67244a09ea7b45e Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Fri, 9 Aug 2024 14:19:29 +0200 Subject: [PATCH] Convert server terminate to signal --- common/rfb/SDesktop.h | 6 ------ common/rfb/VNCServer.h | 4 ++++ common/rfb/VNCServerST.cxx | 8 +++++--- unix/x0vncserver/XDesktop.cxx | 7 +++---- unix/x0vncserver/XDesktop.h | 1 - unix/xserver/hw/vnc/XserverDesktop.cc | 8 +++----- unix/xserver/hw/vnc/XserverDesktop.h | 1 - win/rfb_win32/SDisplay.cxx | 8 +++----- win/rfb_win32/SDisplay.h | 1 - 9 files changed, 18 insertions(+), 26 deletions(-) diff --git a/common/rfb/SDesktop.h b/common/rfb/SDesktop.h index 28f263d1d..5b761dbb7 100644 --- a/common/rfb/SDesktop.h +++ b/common/rfb/SDesktop.h @@ -61,12 +61,6 @@ namespace rfb { virtual void queryConnection(network::Socket* sock, const char* userName) = 0; - // terminate() is called by the server when it wishes to terminate - // itself, e.g. because it was configured to terminate when no one is - // using it. - - virtual void terminate() = 0; - // setScreenLayout() requests to reconfigure the framebuffer and/or // the layout of screens. virtual unsigned int setScreenLayout(int /*fb_width*/, diff --git a/common/rfb/VNCServer.h b/common/rfb/VNCServer.h index d60ab8486..c7240430d 100644 --- a/common/rfb/VNCServer.h +++ b/common/rfb/VNCServer.h @@ -155,6 +155,10 @@ namespace rfb { // clients, and therefore the desktop can cease any expensive // tasks. + // "terminate" is emitted by the server when it wishes to terminate + // itself, e.g. because it was configured to terminate when no one + // is using it. + // "keydown" is emitted whenever the client sends a key press // message. A KeyEvent structure is included with the KeySym and key // code. diff --git a/common/rfb/VNCServerST.cxx b/common/rfb/VNCServerST.cxx index 32fc80721..17da5148f 100644 --- a/common/rfb/VNCServerST.cxx +++ b/common/rfb/VNCServerST.cxx @@ -98,6 +98,8 @@ VNCServerST::VNCServerST(const char* name_, SDesktop* desktop_) registerSignal("start"); registerSignal("stop"); + registerSignal("terminate"); + registerSignal("keydown"); registerSignal("keyup"); registerSignal("pointer"); @@ -747,19 +749,19 @@ void VNCServerST::frameTimeout(core::Timer*, const char*) void VNCServerST::idleTimeout(core::Timer*, const char*) { slog.info("MaxIdleTime reached, exiting"); - desktop->terminate(); + emitSignal("terminate"); } void VNCServerST::disconnectTimeout(core::Timer*, const char*) { slog.info("MaxDisconnectionTime reached, exiting"); - desktop->terminate(); + emitSignal("terminate"); } void VNCServerST::connectTimeout(core::Timer*, const char*) { slog.info("MaxConnectionTime reached, exiting"); - desktop->terminate(); + emitSignal("terminate"); } void VNCServerST::queryConnection(VNCSConnectionST* client, diff --git a/unix/x0vncserver/XDesktop.cxx b/unix/x0vncserver/XDesktop.cxx index e0ef3ed19..123b4da12 100644 --- a/unix/x0vncserver/XDesktop.cxx +++ b/unix/x0vncserver/XDesktop.cxx @@ -243,6 +243,9 @@ void XDesktop::init(VNCServer* vs) server->connectSignal("start", this, &XDesktop::start); server->connectSignal("stop", this, &XDesktop::stop); + server->connectSignal("terminate", this, + []() { kill(getpid(), SIGTERM); }); + server->connectSignal("keydown", this, &XDesktop::keyEvent); server->connectSignal("keyup", this, &XDesktop::keyEvent); server->connectSignal("pointer", this, &XDesktop::pointerEvent); @@ -311,10 +314,6 @@ void XDesktop::stop(VNCServer*, const char*) { pb = nullptr; } -void XDesktop::terminate() { - kill(getpid(), SIGTERM); -} - bool XDesktop::isRunning() { return running; } diff --git a/unix/x0vncserver/XDesktop.h b/unix/x0vncserver/XDesktop.h index 2835e1101..0cf10d397 100644 --- a/unix/x0vncserver/XDesktop.h +++ b/unix/x0vncserver/XDesktop.h @@ -54,7 +54,6 @@ class XDesktop : public rfb::SDesktop, void poll(); // -=- SDesktop interface void init(rfb::VNCServer* vs) override; - void terminate() override; bool isRunning(); void queryConnection(network::Socket* sock, const char* userName) override; diff --git a/unix/xserver/hw/vnc/XserverDesktop.cc b/unix/xserver/hw/vnc/XserverDesktop.cc index ca48b744e..d668fdeee 100644 --- a/unix/xserver/hw/vnc/XserverDesktop.cc +++ b/unix/xserver/hw/vnc/XserverDesktop.cc @@ -88,6 +88,9 @@ XserverDesktop::XserverDesktop(int screenIndex_, server = new VNCServerST(name, this); + server->connectSignal("terminate", this, + []() { kill(getpid(), SIGTERM); }); + server->connectSignal("clipboardrequest", this, &XserverDesktop::handleClipboardRequest); server->connectSignal("clipboardannounce", this, @@ -470,11 +473,6 @@ void XserverDesktop::approveConnection(uint32_t opaqueId, bool accept, // SDesktop callbacks -void XserverDesktop::terminate() -{ - kill(getpid(), SIGTERM); -} - void XserverDesktop::pointerEvent(rfb::VNCServerST*, const char*, rfb::PointerEvent event) { diff --git a/unix/xserver/hw/vnc/XserverDesktop.h b/unix/xserver/hw/vnc/XserverDesktop.h index 7968aac2d..1ddc8a055 100644 --- a/unix/xserver/hw/vnc/XserverDesktop.h +++ b/unix/xserver/hw/vnc/XserverDesktop.h @@ -93,7 +93,6 @@ class XserverDesktop : public rfb::SDesktop, // rfb::SDesktop callbacks void init(rfb::VNCServer* vs) override; - void terminate() override; void queryConnection(network::Socket* sock, const char* userName) override; unsigned int setScreenLayout(int fb_width, int fb_height, diff --git a/win/rfb_win32/SDisplay.cxx b/win/rfb_win32/SDisplay.cxx index 2c15596ea..0dc5a27a9 100644 --- a/win/rfb_win32/SDisplay.cxx +++ b/win/rfb_win32/SDisplay.cxx @@ -104,6 +104,9 @@ void SDisplay::init(VNCServer* vs) server->connectSignal("start", this, &SDisplay::start); server->connectSignal("stop", this, &SDisplay::stop); + server->connectSignal("terminate", this, + [this]() { SetEvent(terminateEvent); }); + server->connectSignal("keydown", this, &SDisplay::keyEvent); server->connectSignal("keyup", this, &SDisplay::keyEvent); server->connectSignal("pointer", this, &SDisplay::pointerEvent); @@ -162,11 +165,6 @@ void SDisplay::stop(VNCServer*, const char*) if (statusLocation) *statusLocation = false; } -void SDisplay::terminate() -{ - SetEvent(terminateEvent); -} - void SDisplay::queryConnection(network::Socket* sock, const char* userName) diff --git a/win/rfb_win32/SDisplay.h b/win/rfb_win32/SDisplay.h index dd075ba1c..4fee82e91 100644 --- a/win/rfb_win32/SDisplay.h +++ b/win/rfb_win32/SDisplay.h @@ -72,7 +72,6 @@ namespace rfb { // -=- SDesktop interface void init(VNCServer* vs) override; - void terminate() override; void queryConnection(network::Socket* sock, const char* userName) override;