From d2f0e2de667fae02e209b91638ba6257f0a65312 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 11 Jan 2013 18:44:02 +0100 Subject: [PATCH] RemoteClient owns the FDWatcher of it's socket --- src/main.cc | 11 ----------- src/remote.cc | 30 ++++++++++++++++-------------- src/remote.hh | 2 +- 3 files changed, 17 insertions(+), 26 deletions(-) diff --git a/src/main.cc b/src/main.cc index 669b0d4c..85a47e9d 100644 --- a/src/main.cc +++ b/src/main.cc @@ -703,17 +703,6 @@ RemoteClient* connect_to(const String& pid, const String& init_command) NCursesUI* ui = new NCursesUI{}; RemoteClient* remote_client = new RemoteClient{sock, ui, init_command}; - new FDWatcher{sock, [=](FDWatcher&) { - try - { - remote_client->process_next_message(); - } - catch (Kakoune::runtime_error& error) - { - ui->print_status(error.description(), -1); - } - }}; - new FDWatcher{0, [=](FDWatcher& ev) { try { diff --git a/src/remote.cc b/src/remote.cc index 03110deb..497ac2a7 100644 --- a/src/remote.cc +++ b/src/remote.cc @@ -294,7 +294,8 @@ DisplayCoord RemoteUI::dimensions() RemoteClient::RemoteClient(int socket, UserInterface* ui, const String& init_command) - : m_socket(socket), m_ui(ui), m_dimensions(ui->dimensions()) + : m_ui(ui), m_dimensions(ui->dimensions()), + m_socket_watcher{socket, [this](FDWatcher&){ process_next_message(); }} { Message msg(socket); msg.write(init_command); @@ -304,35 +305,36 @@ RemoteClient::RemoteClient(int socket, UserInterface* ui, void RemoteClient::process_next_message() { - RemoteUIMsg msg = read(m_socket); + int socket = m_socket_watcher.fd(); + RemoteUIMsg msg = read(socket); switch (msg) { case RemoteUIMsg::PrintStatus: { - auto status = read(m_socket); - auto cursor_pos = read(m_socket); + auto status = read(socket); + auto cursor_pos = read(socket); m_ui->print_status(status, cursor_pos); break; } case RemoteUIMsg::MenuShow: { - auto choices = read_vector(m_socket); - auto anchor = read(m_socket); - auto style = read(m_socket); + auto choices = read_vector(socket); + auto anchor = read(socket); + auto style = read(socket); m_ui->menu_show(choices, anchor, style); break; } case RemoteUIMsg::MenuSelect: - m_ui->menu_select(read(m_socket)); + m_ui->menu_select(read(socket)); break; case RemoteUIMsg::MenuHide: m_ui->menu_hide(); break; case RemoteUIMsg::InfoShow: { - auto choices = read(m_socket); - auto anchor = read(m_socket); - auto style = read(m_socket); + auto choices = read(socket); + auto anchor = read(socket); + auto style = read(socket); m_ui->info_show(choices, anchor, style); break; } @@ -341,8 +343,8 @@ void RemoteClient::process_next_message() break; case RemoteUIMsg::Draw: { - DisplayBuffer display_buffer = read(m_socket); - String mode_line = read(m_socket); + DisplayBuffer display_buffer = read(socket); + String mode_line = read(socket); m_ui->draw(display_buffer, mode_line); break; } @@ -351,7 +353,7 @@ void RemoteClient::process_next_message() void RemoteClient::write_next_key() { - Message msg(m_socket); + Message msg(m_socket_watcher.fd()); // do that before checking dimensions as get_key may // handle a resize event. msg.write(m_ui->get_key()); diff --git a/src/remote.hh b/src/remote.hh index 7024dc4a..b7a26681 100644 --- a/src/remote.hh +++ b/src/remote.hh @@ -22,9 +22,9 @@ public: void write_next_key(); private: - int m_socket; std::unique_ptr m_ui; DisplayCoord m_dimensions; + FDWatcher m_socket_watcher; }; }