Use a seperate thread for STDIO capture for groups

When running the plugins on the main thread the window message loop may
block for a while, which would cause the STDIO redirect to be
interrupted.
This commit is contained in:
Robbert van der Helm
2020-05-25 15:15:32 +02:00
parent 23f15c8d8a
commit bbfe522343
2 changed files with 29 additions and 2 deletions
+10 -2
View File
@@ -92,8 +92,9 @@ GroupBridge::GroupBridge(boost::filesystem::path group_socket_path)
: logger(Logger::create_from_environment(
create_logger_prefix(group_socket_path))),
io_context(),
stdout_redirect(io_context, STDOUT_FILENO),
stderr_redirect(io_context, STDERR_FILENO),
stdio_context(),
stdout_redirect(stdio_context, STDOUT_FILENO),
stderr_redirect(stdio_context, STDERR_FILENO),
group_socket_endpoint(group_socket_path.string()),
group_socket_acceptor(
create_acceptor_if_inactive(io_context, group_socket_endpoint)),
@@ -101,6 +102,13 @@ GroupBridge::GroupBridge(boost::filesystem::path group_socket_path)
// Write this process's original STDOUT and STDERR streams to the logger
async_log_pipe_lines(stdout_redirect.pipe, stdout_buffer, "[STDOUT] ");
async_log_pipe_lines(stderr_redirect.pipe, stderr_buffer, "[STDERR] ");
stdio_handler = std::thread([&]() { stdio_context.run(); });
}
GroupBridge::~GroupBridge() {
stdio_context.stop();
stdio_handler.join();
}
void GroupBridge::handle_host_plugin(const GroupRequest request) {