Skip to content

Commit

Permalink
Merge #62
Browse files Browse the repository at this point in the history
#62: windows/console: Use select() on session socket for read detection r=townsend2010 a=Saviq
  • Loading branch information
Saviq committed Nov 15, 2018
2 parents f39ef22 + 2674d0d commit ae206af
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/platform/console/windows_console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#include <multipass/cli/client_platform.h>

#include <winsock2.h>

#include <array>
#include <mutex>

Expand Down Expand Up @@ -82,6 +84,7 @@ mp::WindowsConsole::WindowsConsole(ssh_channel channel)
input_handle{GetStdHandle(STD_INPUT_HANDLE)},
output_handle{GetStdHandle(STD_OUTPUT_HANDLE)},
channel{channel},
session_socket_fd{ssh_get_fd(ssh_channel_get_session(channel))},
console_event_thread{[this] { monitor_console_resize(hook); }}
{
global_channel = channel;
Expand All @@ -107,7 +110,7 @@ void mp::WindowsConsole::setup_console()

void mp::WindowsConsole::read_console()
{
std::array<char, 1024> buffer;
std::array<char, 4096> buffer;
int bytes_read{0};

FlushConsoleInputBuffer(input_handle);
Expand All @@ -120,10 +123,14 @@ void mp::WindowsConsole::read_console()
void mp::WindowsConsole::write_console()
{
DWORD write;
std::array<char, 1024> buffer;
std::array<char, 4096> buffer;
int num_bytes{0};
fd_set read_set;

FD_ZERO(&read_set);
FD_SET(session_socket_fd, &read_set);

if (ssh_channel_poll(channel, 0) < 1)
if (select(0, &read_set, nullptr, nullptr, nullptr) < 1)
return;

{
Expand Down
1 change: 1 addition & 0 deletions src/platform/console/windows_console.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class WindowsConsole final : public Console
DWORD console_input_mode;
DWORD console_output_mode;
ssh_channel channel;
socket_t session_socket_fd;
HWINEVENTHOOK hook;
std::thread console_event_thread;
};
Expand Down
1 change: 0 additions & 1 deletion src/ssh/ssh_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ int mp::SSHClient::exec(const std::vector<std::string>& args)

void mp::SSHClient::handle_ssh_events()
{
using ConnectorUPtr = std::unique_ptr<ssh_connector_struct, void (*)(ssh_connector)>;
#ifndef MULTIPASS_PLATFORM_WINDOWS
using ConnectorUPtr = std::unique_ptr<ssh_connector_struct, void (*)(ssh_connector)>;
std::unique_ptr<ssh_event_struct, void (*)(ssh_event)> event{ssh_event_new(), ssh_event_free};
Expand Down

0 comments on commit ae206af

Please sign in to comment.