From 1d790541f5e171156e79835654f7609bf5e71176 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 28 Aug 2013 19:19:54 +0100 Subject: [PATCH] handle client disconnection without crashing --- src/remote.cc | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/remote.cc b/src/remote.cc index e798ee2b2..39542a0b4 100644 --- a/src/remote.cc +++ b/src/remote.cc @@ -335,13 +335,25 @@ bool RemoteUI::is_key_available() Key RemoteUI::get_key() { - Key key = read(m_socket_watcher.fd()); - if (key.modifiers == resize_modifier) + try { - m_dimensions = { (int)(key.key >> 16), (int)(key.key & 0xFFFF) }; - return Key::Invalid; + Key key = read(m_socket_watcher.fd()); + if (key.modifiers == resize_modifier) + { + m_dimensions = { (int)(key.key >> 16), (int)(key.key & 0xFFFF) }; + return Key::Invalid; + } + return key; + } + catch (peer_disconnected&) + { + throw client_removed{}; + } + catch (socket_error&) + { + write_debug("ungraceful deconnection detected"); + throw client_removed{}; } - return key; } DisplayCoord RemoteUI::dimensions()