mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-06-18 01:13:55 +02:00
Replace Boost.Asio with standalone Asio library
We had to add an even hackier hack now to get Boost.Process to interoperate with Asio's IO contexts. This will be replaced later when we replace Boost.Process.
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../boost-fix.h"
|
||||
#include "../asio-fix.h"
|
||||
|
||||
#include <ghc/filesystem.hpp>
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
#include "group.h"
|
||||
|
||||
#include "../boost-fix.h"
|
||||
#include "../asio-fix.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <regex>
|
||||
@@ -49,23 +49,23 @@ using namespace std::literals::chrono_literals;
|
||||
* @throw std::runtime_error If another process is already listening on the
|
||||
* endpoint.
|
||||
*/
|
||||
boost::asio::local::stream_protocol::acceptor create_acceptor_if_inactive(
|
||||
boost::asio::io_context& io_context,
|
||||
boost::asio::local::stream_protocol::endpoint& endpoint);
|
||||
asio::local::stream_protocol::acceptor create_acceptor_if_inactive(
|
||||
asio::io_context& io_context,
|
||||
asio::local::stream_protocol::endpoint& endpoint);
|
||||
|
||||
/**
|
||||
* Create a logger prefix containing the group name based on the socket path.
|
||||
*/
|
||||
std::string create_logger_prefix(const fs::path& socket_path);
|
||||
|
||||
StdIoCapture::StdIoCapture(boost::asio::io_context& io_context,
|
||||
int file_descriptor)
|
||||
StdIoCapture::StdIoCapture(asio::io_context& io_context, int file_descriptor)
|
||||
: pipe_(io_context),
|
||||
target_fd_(file_descriptor),
|
||||
original_fd_copy_(dup(file_descriptor)) {
|
||||
// We'll use the second element of these two file descriptors to reopen
|
||||
// `file_descriptor`, and the first one to read the captured contents from
|
||||
if (::pipe(pipe_fd_) != 0) {
|
||||
std::cerr << "Could not create pipe" << std::endl;
|
||||
throw std::system_error(errno, std::system_category());
|
||||
}
|
||||
|
||||
@@ -171,12 +171,12 @@ void GroupBridge::handle_incoming_connections() {
|
||||
|
||||
void GroupBridge::accept_requests() {
|
||||
group_socket_acceptor_.async_accept(
|
||||
[&](const boost::system::error_code& error,
|
||||
boost::asio::local::stream_protocol::socket socket) {
|
||||
[&](const std::error_code& error,
|
||||
asio::local::stream_protocol::socket socket) {
|
||||
std::lock_guard lock(active_plugins_mutex_);
|
||||
|
||||
// Stop the whole process when the socket gets closed unexpectedly
|
||||
if (error.failed()) {
|
||||
if (error) {
|
||||
logger_.log("Error while listening for incoming connections:");
|
||||
logger_.log(error.message());
|
||||
|
||||
@@ -284,14 +284,13 @@ void GroupBridge::async_handle_events() {
|
||||
[&]() { return !is_event_loop_inhibited(); });
|
||||
}
|
||||
|
||||
boost::asio::local::stream_protocol::acceptor create_acceptor_if_inactive(
|
||||
boost::asio::io_context& io_context,
|
||||
boost::asio::local::stream_protocol::endpoint& endpoint) {
|
||||
asio::local::stream_protocol::acceptor create_acceptor_if_inactive(
|
||||
asio::io_context& io_context,
|
||||
asio::local::stream_protocol::endpoint& endpoint) {
|
||||
// First try to listen on the endpoint normally
|
||||
try {
|
||||
return boost::asio::local::stream_protocol::acceptor(io_context,
|
||||
endpoint);
|
||||
} catch (const boost::system::system_error&) {
|
||||
return asio::local::stream_protocol::acceptor(io_context, endpoint);
|
||||
} catch (const std::system_error&) {
|
||||
// If this failed, then either there is a stale socket file or another
|
||||
// process is already is already listening. In the last case we will
|
||||
// simply throw so the other process can handle the request.
|
||||
@@ -312,8 +311,7 @@ boost::asio::local::stream_protocol::acceptor create_acceptor_if_inactive(
|
||||
|
||||
// At this point we can remove the stale socket and start listening
|
||||
fs::remove(endpoint_path);
|
||||
return boost::asio::local::stream_protocol::acceptor(io_context,
|
||||
endpoint);
|
||||
return asio::local::stream_protocol::acceptor(io_context, endpoint);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,10 +320,10 @@ void GroupBridge::maybe_schedule_shutdown(
|
||||
std::lock_guard lock(shutdown_timer_mutex_);
|
||||
|
||||
shutdown_timer_.expires_after(delay);
|
||||
shutdown_timer_.async_wait([this](const boost::system::error_code& error) {
|
||||
shutdown_timer_.async_wait([this](const std::error_code& error) {
|
||||
// A previous timer gets canceled automatically when another plugin
|
||||
// exits
|
||||
if (error.failed()) {
|
||||
if (error) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
|
||||
#include "../boost-fix.h"
|
||||
#include "../asio-fix.h"
|
||||
|
||||
#include <boost/asio/local/stream_protocol.hpp>
|
||||
#include <asio/local/stream_protocol.hpp>
|
||||
|
||||
#include "../common/logging/common.h"
|
||||
#include "../utils.h"
|
||||
@@ -49,7 +49,7 @@ class StdIoCapture {
|
||||
*
|
||||
* @throw std::system_error If the pipe could not be created.
|
||||
*/
|
||||
StdIoCapture(boost::asio::io_context& io_context, int file_descriptor);
|
||||
StdIoCapture(asio::io_context& io_context, int file_descriptor);
|
||||
|
||||
/**
|
||||
* On cleanup, close the outgoing file descriptor from the pipe and restore
|
||||
@@ -65,9 +65,9 @@ class StdIoCapture {
|
||||
|
||||
/**
|
||||
* The pipe endpoint where all output from the original file descriptor gets
|
||||
* redirected to. This can be read from like any other `Boost.Asio` stream.
|
||||
* redirected to. This can be read from like any other Asio stream.
|
||||
*/
|
||||
boost::asio::posix::stream_descriptor pipe_;
|
||||
asio::posix::stream_descriptor pipe_;
|
||||
|
||||
private:
|
||||
/**
|
||||
@@ -116,7 +116,7 @@ class GroupBridge {
|
||||
* where `<wine_prefix_id>` is a numerical hash as explained in the
|
||||
* `create_logger_prefix()` function in `./group.cpp`.
|
||||
*
|
||||
* @throw boost::system::system_error If we can't listen on the socket.
|
||||
* @throw std::system_error If we can't listen on the socket.
|
||||
* @throw std::system_error If the pipe could not be created.
|
||||
*
|
||||
* @note Creating an `GroupBridge` instance has the side effect that the
|
||||
@@ -220,10 +220,10 @@ class GroupBridge {
|
||||
* related operation should be run from the same thread, we can't just add
|
||||
* another thread to the main IO context.
|
||||
*/
|
||||
boost::asio::io_context stdio_context_;
|
||||
asio::io_context stdio_context_;
|
||||
|
||||
boost::asio::streambuf stdout_buffer_;
|
||||
boost::asio::streambuf stderr_buffer_;
|
||||
asio::streambuf stdout_buffer_;
|
||||
asio::streambuf stderr_buffer_;
|
||||
/**
|
||||
* Contains a pipe used for capturing this process's STDOUT stream. Needed
|
||||
* to be able to process the output generated by Wine and plugins and to be
|
||||
@@ -241,12 +241,12 @@ class GroupBridge {
|
||||
*/
|
||||
Win32Thread stdio_handler_;
|
||||
|
||||
boost::asio::local::stream_protocol::endpoint group_socket_endpoint_;
|
||||
asio::local::stream_protocol::endpoint group_socket_endpoint_;
|
||||
/**
|
||||
* The UNIX domain socket acceptor that will be used to listen for incoming
|
||||
* connections to spawn new plugins within this process.
|
||||
*/
|
||||
boost::asio::local::stream_protocol::acceptor group_socket_acceptor_;
|
||||
asio::local::stream_protocol::acceptor group_socket_acceptor_;
|
||||
|
||||
/**
|
||||
* A map of threads that are currently hosting a plugin within this process
|
||||
@@ -281,7 +281,7 @@ class GroupBridge {
|
||||
*
|
||||
* @see handle_plugin_run
|
||||
*/
|
||||
boost::asio::steady_timer shutdown_timer_;
|
||||
asio::steady_timer shutdown_timer_;
|
||||
/**
|
||||
* A mutex to prevent two threads from simultaneously modifying the shutdown
|
||||
* timer when multiple plugins exit at the same time.
|
||||
|
||||
@@ -623,7 +623,7 @@ class HostCallbackDataConverter : public DefaultDataConverter {
|
||||
}
|
||||
|
||||
Vst2EventResult send_event(
|
||||
boost::asio::local::stream_protocol::socket& socket,
|
||||
asio::local::stream_protocol::socket& socket,
|
||||
const Vst2Event& event,
|
||||
SerializationBufferBase& buffer) const override {
|
||||
if (mutually_recursive_callbacks.contains(event.opcode)) {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../boost-fix.h"
|
||||
#include "../asio-fix.h"
|
||||
|
||||
#include <vestige/aeffectx.h>
|
||||
#include <windows.h>
|
||||
|
||||
Reference in New Issue
Block a user