diff options
| author | Maxime Coste <mawww@kakoune.org> | 2018-04-29 22:27:28 +1000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2018-04-29 22:31:57 +1000 |
| commit | 178d2d3cd354bc93d82e5cd6269976b2077a66c3 (patch) | |
| tree | a5e7095f74b6d09c6cd32f5d780d3928acce899e /src/remote.cc | |
| parent | 57112b0845a0ee9957d156fd3812a716c4d97a2c (diff) | |
Rework the way UI can trigger a client quitting
Add a UserInterface::is_ok method and return false on
SIGHUP/stdin closing/socket dropping
This should be cleaner and more robust than the previous SIGHUP
handling code.
Fixes #1594
Diffstat (limited to 'src/remote.cc')
| -rw-r--r-- | src/remote.cc | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/src/remote.cc b/src/remote.cc index d3879f28..6a717805 100644 --- a/src/remote.cc +++ b/src/remote.cc @@ -315,6 +315,7 @@ public: RemoteUI(int socket, DisplayCoord dimensions); ~RemoteUI() override; + bool is_ok() const override { return m_socket_watcher.fd() != -1; } void menu_show(ConstArrayView<DisplayLine> choices, DisplayCoord anchor, Face fg, Face bg, MenuStyle style) override; @@ -345,9 +346,6 @@ public: void set_ui_options(const Options& options) override; - void set_client(Client* client) { m_client = client; } - Client* client() const { return m_client.get(); } - void exit(int status); private: @@ -356,8 +354,6 @@ private: DisplayCoord m_dimensions; OnKeyCallback m_on_key; RemoteBuffer m_send_buffer; - - SafePtr<Client> m_client; }; static bool send_data(int fd, RemoteBuffer& buffer) @@ -390,8 +386,8 @@ RemoteUI::RemoteUI(int socket, DisplayCoord dimensions) if (m_reader.type() != MessageType::Key) { - ClientManager::instance().remove_client(*m_client, false, -1); - return; + m_socket_watcher.close_fd(); + return; } auto key = m_reader.read<Key>(); @@ -404,7 +400,7 @@ RemoteUI::RemoteUI(int socket, DisplayCoord dimensions) catch (const disconnected& err) { write_to_debug_buffer(format("Error while transfering remote messages: {}", err.what())); - ClientManager::instance().remove_client(*m_client, false, -1); + m_socket_watcher.close_fd(); } }), m_dimensions(dimensions) @@ -725,11 +721,10 @@ private: auto dimensions = m_reader.read<DisplayCoord>(); auto env_vars = m_reader.read_hash_map<String, String, MemoryDomain::EnvVars>(); auto* ui = new RemoteUI{sock, dimensions}; - if (auto* client = ClientManager::instance().create_client( - std::unique_ptr<UserInterface>(ui), pid, std::move(name), - std::move(env_vars), init_cmds, init_coord, - [ui](int status) { ui->exit(status); })) - ui->set_client(client); + ClientManager::instance().create_client( + std::unique_ptr<UserInterface>(ui), pid, std::move(name), + std::move(env_vars), init_cmds, init_coord, + [ui](int status) { ui->exit(status); }); Server::instance().remove_accepter(this); break; |
