From e889ad22e202c1323eafe0ecba6f692bbda40c54 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Fri, 4 Dec 2020 14:03:07 +0100 Subject: [PATCH] Only pass Logger reference to AdHocSocketHandler The boolean flag wasn't used, and it doesn't make any sense in the context of VST3. --- src/common/communication/common.h | 32 +++++++++++++++---------------- src/common/communication/vst2.h | 2 +- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/common/communication/common.h b/src/common/communication/common.h index bcdbed84..26af855b 100644 --- a/src/common/communication/common.h +++ b/src/common/communication/common.h @@ -531,9 +531,8 @@ class AdHocSocketHandler { * then a blocking loop that handles incoming data from the primary * `socket`. * - * @param logging A pair containing a logger instance and whether or not - * this is for sending `dispatch()` events or host callbacks. Optional - * since it doesn't have to be done on both sides. + * @param logger A logger instance for logging connection errors. This + * should only be passed on the plugin side. * @param primary_callback A function that will do a single read cycle for * the primary socket socket that should do a single read cycle. This is * called in a loop so it shouldn't do any looping itself. @@ -547,7 +546,7 @@ class AdHocSocketHandler { * @tparam G The same as `F`. */ template - void receive_multi(std::optional> logging, + void receive_multi(std::optional> logger, F primary_callback, G secondary_callback) { // As described above we'll handle incoming requests for `socket` on @@ -568,7 +567,7 @@ class AdHocSocketHandler { std::atomic_size_t next_request_id{}; std::mutex active_secondary_requests_mutex{}; accept_requests( - *acceptor, logging, + *acceptor, logger, [&](boost::asio::local::stream_protocol::socket secondary_socket) { const size_t request_id = next_request_id.fetch_add(1); @@ -624,9 +623,9 @@ class AdHocSocketHandler { * @overload */ template - void receive_multi(std::optional> logging, + void receive_multi(std::optional> logger, F callback) { - receive_multi(logging, callback, callback); + receive_multi(logger, callback, callback); } private: @@ -636,9 +635,8 @@ class AdHocSocketHandler { * called until the IO context gets stopped. * * @param acceptor The acceptor we will be listening on. - * @param logging A pair containing a logger instance and whether or not - * this is for sending `dispatch()` events or host callbacks. Optional - * since it doesn't have to be done on both sides. + * @param logger A logger instance for logging connection errors. This + * should only be passed on the plugin side. * @param callback A function that handles the new socket connection. * * @tparam F A function in the form @@ -648,10 +646,10 @@ class AdHocSocketHandler { template void accept_requests( boost::asio::local::stream_protocol::acceptor& acceptor, - std::optional> logging, + std::optional> logger, F callback) { acceptor.async_accept( - [&, logging, callback]( + [&, logger, callback]( const boost::system::error_code& error, boost::asio::local::stream_protocol::socket secondary_socket) { if (error.failed()) { @@ -659,10 +657,10 @@ class AdHocSocketHandler { // connection will be dropped during shutdown, so we can // silently ignore any related socket errors on the Wine // side - if (logging) { - auto [logger, is_dispatch] = *logging; - logger.log("Failure while accepting connections: " + - error.message()); + if (logger) { + logger->get().log( + "Failure while accepting connections: " + + error.message()); } return; @@ -670,7 +668,7 @@ class AdHocSocketHandler { callback(std::move(secondary_socket)); - accept_requests(acceptor, logging, callback); + accept_requests(acceptor, logger, callback); }); } diff --git a/src/common/communication/vst2.h b/src/common/communication/vst2.h index 8ecab67b..f3304449 100644 --- a/src/common/communication/vst2.h +++ b/src/common/communication/vst2.h @@ -254,7 +254,7 @@ class EventHandler : public AdHocSocketHandler { }; this->receive_multi( - logging, + logging ? std::optional(std::ref(logging->first)) : std::nullopt, [&](boost::asio::local::stream_protocol::socket& socket) { process_event(socket, true); },