summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2013-01-11 18:44:02 +0100
committerMaxime Coste <frrrwww@gmail.com>2013-01-11 18:44:02 +0100
commitd2f0e2de667fae02e209b91638ba6257f0a65312 (patch)
treebf029d38b7f6be1cf2019b4a03253858d102f170 /src
parent914ede7a8258962990a7c24fac0e451bc7c1d7a6 (diff)
RemoteClient owns the FDWatcher of it's socket
Diffstat (limited to 'src')
-rw-r--r--src/main.cc11
-rw-r--r--src/remote.cc30
-rw-r--r--src/remote.hh2
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<RemoteUIMsg>(m_socket);
+ int socket = m_socket_watcher.fd();
+ RemoteUIMsg msg = read<RemoteUIMsg>(socket);
switch (msg)
{
case RemoteUIMsg::PrintStatus:
{
- auto status = read<String>(m_socket);
- auto cursor_pos = read<CharCount>(m_socket);
+ auto status = read<String>(socket);
+ auto cursor_pos = read<CharCount>(socket);
m_ui->print_status(status, cursor_pos);
break;
}
case RemoteUIMsg::MenuShow:
{
- auto choices = read_vector<String>(m_socket);
- auto anchor = read<DisplayCoord>(m_socket);
- auto style = read<MenuStyle>(m_socket);
+ auto choices = read_vector<String>(socket);
+ auto anchor = read<DisplayCoord>(socket);
+ auto style = read<MenuStyle>(socket);
m_ui->menu_show(choices, anchor, style);
break;
}
case RemoteUIMsg::MenuSelect:
- m_ui->menu_select(read<int>(m_socket));
+ m_ui->menu_select(read<int>(socket));
break;
case RemoteUIMsg::MenuHide:
m_ui->menu_hide();
break;
case RemoteUIMsg::InfoShow:
{
- auto choices = read<String>(m_socket);
- auto anchor = read<DisplayCoord>(m_socket);
- auto style = read<MenuStyle>(m_socket);
+ auto choices = read<String>(socket);
+ auto anchor = read<DisplayCoord>(socket);
+ auto style = read<MenuStyle>(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<DisplayBuffer>(m_socket);
- String mode_line = read<String>(m_socket);
+ DisplayBuffer display_buffer = read<DisplayBuffer>(socket);
+ String mode_line = read<String>(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<UserInterface> m_ui;
DisplayCoord m_dimensions;
+ FDWatcher m_socket_watcher;
};
}