diff --git a/src/remote.cc b/src/remote.cc index 72e3425f..a72437ad 100644 --- a/src/remote.cc +++ b/src/remote.cc @@ -396,7 +396,7 @@ RemoteClient::RemoteClient(int socket, std::unique_ptr&& ui, const EnvVarMap& env_vars, const String& init_command) : m_ui(std::move(ui)), m_dimensions(m_ui->dimensions()), - m_socket_watcher{socket, [this](FDWatcher&){ process_next_message(); }} + m_socket_watcher{socket, [this](FDWatcher&){ process_available_messages(); }} { Message msg(socket); msg.write(init_command.c_str(), (int)init_command.length()+1); @@ -409,6 +409,20 @@ RemoteClient::RemoteClient(int socket, std::unique_ptr&& ui, m_ui->set_input_callback([this]{ write_next_key(); }); } +void RemoteClient::process_available_messages() +{ + int socket = m_socket_watcher.fd(); + timeval tv{ 0, 0 }; + fd_set rfds; + + do { + process_next_message(); + + FD_ZERO(&rfds); + FD_SET(socket, &rfds); + } while (select(socket+1, &rfds, nullptr, nullptr, &tv) == 1); +} + void RemoteClient::process_next_message() { int socket = m_socket_watcher.fd(); diff --git a/src/remote.hh b/src/remote.hh index cebd56cf..f99b297f 100644 --- a/src/remote.hh +++ b/src/remote.hh @@ -27,6 +27,7 @@ public: const EnvVarMap& env_vars, const String& init_command); private: + void process_available_messages(); void process_next_message(); void write_next_key();