Skip to content

Commit

Permalink
Convert server terminate to signal
Browse files Browse the repository at this point in the history
  • Loading branch information
CendioOssman committed Aug 13, 2024
1 parent 6dba91c commit 2804ea1
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 26 deletions.
6 changes: 0 additions & 6 deletions common/rfb/SDesktop.h
Original file line number Diff line number Diff line change
Expand Up @@ -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*/,
Expand Down
4 changes: 4 additions & 0 deletions common/rfb/VNCServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 5 additions & 3 deletions common/rfb/VNCServerST.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ VNCServerST::VNCServerST(const char* name_, SDesktop* desktop_)
registerSignal("start");
registerSignal("stop");

registerSignal("terminate");

registerSignal<KeyEvent>("keydown");
registerSignal<KeyEvent>("keyup");
registerSignal<PointerEvent>("pointer");
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 3 additions & 4 deletions unix/x0vncserver/XDesktop.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -311,10 +314,6 @@ void XDesktop::stop(VNCServer*, const char*) {
pb = nullptr;
}

void XDesktop::terminate() {
kill(getpid(), SIGTERM);
}

bool XDesktop::isRunning() {
return running;
}
Expand Down
1 change: 0 additions & 1 deletion unix/x0vncserver/XDesktop.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 3 additions & 5 deletions unix/xserver/hw/vnc/XserverDesktop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
{
Expand Down
1 change: 0 additions & 1 deletion unix/xserver/hw/vnc/XserverDesktop.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 3 additions & 5 deletions win/rfb_win32/SDisplay.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion win/rfb_win32/SDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 2804ea1

Please sign in to comment.