RemoteClient process all available messages

This commit is contained in:
Maxime Coste 2014-04-15 19:08:47 +01:00
parent 374f97a592
commit 98c6a6f17e
2 changed files with 16 additions and 1 deletions

View File

@ -396,7 +396,7 @@ RemoteClient::RemoteClient(int socket, std::unique_ptr<UserInterface>&& ui,
const EnvVarMap& env_vars, const EnvVarMap& env_vars,
const String& init_command) const String& init_command)
: m_ui(std::move(ui)), m_dimensions(m_ui->dimensions()), : 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); Message msg(socket);
msg.write(init_command.c_str(), (int)init_command.length()+1); msg.write(init_command.c_str(), (int)init_command.length()+1);
@ -409,6 +409,20 @@ RemoteClient::RemoteClient(int socket, std::unique_ptr<UserInterface>&& ui,
m_ui->set_input_callback([this]{ write_next_key(); }); 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() void RemoteClient::process_next_message()
{ {
int socket = m_socket_watcher.fd(); int socket = m_socket_watcher.fd();

View File

@ -27,6 +27,7 @@ public:
const EnvVarMap& env_vars, const String& init_command); const EnvVarMap& env_vars, const String& init_command);
private: private:
void process_available_messages();
void process_next_message(); void process_next_message();
void write_next_key(); void write_next_key();