mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-09 20:29:10 +02:00
Reintroduce the additional IO contexts
Having these bound to the main context was not a good idea since that
would prevent sockets from being accepted on the Wine side while the
message loop is running.
Partial revert of ac17539ef3
This commit is contained in:
@@ -206,9 +206,9 @@ class EventHandler {
|
|||||||
* Sets up a single main socket for this type of events. The sockets won't
|
* Sets up a single main socket for this type of events. The sockets won't
|
||||||
* be active until `connect()` gets called.
|
* be active until `connect()` gets called.
|
||||||
*
|
*
|
||||||
* @param io_context The IO context the sockets should be bound to.
|
* @param io_context The IO context the main socket should be bound to. A
|
||||||
* Additional incoming connections will be handled asynchronously within
|
* new IO context will be created for accepting the additional incoming
|
||||||
* this IO context.
|
* connections.
|
||||||
* @param endpoint The socket endpoint used for this event handler.
|
* @param endpoint The socket endpoint used for this event handler.
|
||||||
* @param listen If `true`, start listening on the sockets. Incoming
|
* @param listen If `true`, start listening on the sockets. Incoming
|
||||||
* connections will be accepted when `connect()` gets called. This should
|
* connections will be accepted when `connect()` gets called. This should
|
||||||
@@ -356,9 +356,11 @@ class EventHandler {
|
|||||||
// thread to handle the request. When `socket` closes and this loop
|
// thread to handle the request. When `socket` closes and this loop
|
||||||
// breaks, the listener and any still active threads will be cleaned up
|
// breaks, the listener and any still active threads will be cleaned up
|
||||||
// before this function exits.
|
// before this function exits.
|
||||||
|
boost::asio::io_context secondary_context{};
|
||||||
|
|
||||||
// The previous acceptor has already been shut down by
|
// The previous acceptor has already been shut down by
|
||||||
// `EventHandler::connect()`
|
// `EventHandler::connect()`
|
||||||
acceptor.emplace(io_context, endpoint);
|
acceptor.emplace(secondary_context, endpoint);
|
||||||
|
|
||||||
// This works the exact same was as `active_plugins` and
|
// This works the exact same was as `active_plugins` and
|
||||||
// `next_plugin_id` in `GroupBridge`
|
// `next_plugin_id` in `GroupBridge`
|
||||||
@@ -400,7 +402,7 @@ class EventHandler {
|
|||||||
// When we have processed this request, we'll join the
|
// When we have processed this request, we'll join the
|
||||||
// thread again with the thread that's handling
|
// thread again with the thread that's handling
|
||||||
// `secondary_context`.
|
// `secondary_context`.
|
||||||
boost::asio::post(io_context, [&, request_id]() {
|
boost::asio::post(secondary_context, [&, request_id]() {
|
||||||
std::lock_guard lock(
|
std::lock_guard lock(
|
||||||
active_secondary_requests_mutex);
|
active_secondary_requests_mutex);
|
||||||
|
|
||||||
@@ -412,6 +414,9 @@ class EventHandler {
|
|||||||
std::move(secondary_socket));
|
std::move(secondary_socket));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
std::jthread secondary_requests_handler(
|
||||||
|
[&]() { secondary_context.run(); });
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
auto event = read_object<Event>(socket);
|
auto event = read_object<Event>(socket);
|
||||||
@@ -442,6 +447,7 @@ class EventHandler {
|
|||||||
// sure all outstanding jobs have been processed and then drop all work
|
// sure all outstanding jobs have been processed and then drop all work
|
||||||
// from the IO context
|
// from the IO context
|
||||||
std::lock_guard lock(active_secondary_requests_mutex);
|
std::lock_guard lock(active_secondary_requests_mutex);
|
||||||
|
secondary_context.stop();
|
||||||
acceptor.reset();
|
acceptor.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -491,10 +497,9 @@ class EventHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main IO context for this application. New sockets created during
|
* The main IO context. New sockets created during `send()` will be bound to
|
||||||
* `send()` will be bound to this context, and in `receive()` we'll
|
* this context. In `receive()` we'll create a new IO context since we want
|
||||||
* asynchronously listen for additional incoming connections through this
|
* to do all listening there on a dedicated thread.
|
||||||
* context.
|
|
||||||
*/
|
*/
|
||||||
boost::asio::io_context& io_context;
|
boost::asio::io_context& io_context;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user