mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-06-15 16:03:55 +02:00
Properly move the sockets to the handler threads
At times like this you really wish you were writing Rust right now.
This commit is contained in:
@@ -116,7 +116,7 @@ inline T read_object(Socket& socket,
|
|||||||
{buffer.begin(), size}, object);
|
{buffer.begin(), size}, object);
|
||||||
|
|
||||||
if (BOOST_UNLIKELY(!success)) {
|
if (BOOST_UNLIKELY(!success)) {
|
||||||
throw std::runtime_error("Deserialization failure in call:" +
|
throw std::runtime_error("Deserialization failure in call: " +
|
||||||
std::string(__PRETTY_FUNCTION__));
|
std::string(__PRETTY_FUNCTION__));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -370,9 +370,12 @@ class EventHandler {
|
|||||||
[&](boost::asio::local::stream_protocol::socket secondary_socket) {
|
[&](boost::asio::local::stream_protocol::socket secondary_socket) {
|
||||||
const size_t request_id = next_request_id.fetch_add(1);
|
const size_t request_id = next_request_id.fetch_add(1);
|
||||||
|
|
||||||
|
// We have to make sure to keep moving these sockets into the
|
||||||
|
// threads that will handle them
|
||||||
std::lock_guard lock(active_secondary_requests_mutex);
|
std::lock_guard lock(active_secondary_requests_mutex);
|
||||||
active_secondary_requests[request_id] =
|
active_secondary_requests[request_id] = std::jthread(
|
||||||
std::jthread([&, request_id]() {
|
[&, request_id](boost::asio::local::stream_protocol::socket
|
||||||
|
secondary_socket) {
|
||||||
// TODO: Factor this out
|
// TODO: Factor this out
|
||||||
auto event = read_object<Event>(secondary_socket);
|
auto event = read_object<Event>(secondary_socket);
|
||||||
if (logging) {
|
if (logging) {
|
||||||
@@ -405,7 +408,8 @@ class EventHandler {
|
|||||||
// std::jthread
|
// std::jthread
|
||||||
active_secondary_requests.erase(request_id);
|
active_secondary_requests.erase(request_id);
|
||||||
});
|
});
|
||||||
});
|
},
|
||||||
|
std::move(secondary_socket));
|
||||||
});
|
});
|
||||||
|
|
||||||
std::jthread secondary_requests_handler(
|
std::jthread secondary_requests_handler(
|
||||||
@@ -465,9 +469,9 @@ class EventHandler {
|
|||||||
std::optional<std::pair<Logger&, bool>> logging,
|
std::optional<std::pair<Logger&, bool>> logging,
|
||||||
F callback) {
|
F callback) {
|
||||||
acceptor.async_accept(
|
acceptor.async_accept(
|
||||||
[&](const boost::system::error_code& error,
|
[&, logging, callback](
|
||||||
|
const boost::system::error_code& error,
|
||||||
boost::asio::local::stream_protocol::socket secondary_socket) {
|
boost::asio::local::stream_protocol::socket secondary_socket) {
|
||||||
//
|
|
||||||
if (error.failed()) {
|
if (error.failed()) {
|
||||||
if (logging) {
|
if (logging) {
|
||||||
auto [logger, is_dispatch] = *logging;
|
auto [logger, is_dispatch] = *logging;
|
||||||
|
|||||||
Reference in New Issue
Block a user