From 5c946fff6a9ccc99b5cbac3a166ef1d29fefd28f Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Mon, 24 Feb 2020 16:43:04 +0100 Subject: [PATCH] Communicate over the socket instead of STDIN --- src/common/communication.h | 25 ++++++++++++------------- src/plugin/bridge.cpp | 4 ++-- src/wine-host/vst-host.cpp | 4 ++-- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/common/communication.h b/src/common/communication.h index 705df8b6..8ffa0a85 100644 --- a/src/common/communication.h +++ b/src/common/communication.h @@ -16,6 +16,7 @@ #pragma once +#include #include #include #include @@ -66,15 +67,14 @@ struct EventResult { * * @relates read_object */ -template -inline void write_object(Stream& stream, const T& object) { +template +inline void write_object(Socket& socket, const T& object) { // TODO: Reuse buffers + // TODO: Use boost's buffers directly after switching to bitsery msgpack::sbuffer buffer; msgpack::pack(buffer, object); - stream << buffer.size(); - stream.write(buffer.data(), buffer.size()); - stream.flush(); + socket.send(boost::asio::buffer(buffer.data(), buffer.size())); } /** @@ -87,13 +87,12 @@ inline void write_object(Stream& stream, const T& object) { * * @relates write_object */ -template -inline T read_object(Stream& stream) { - size_t message_length; - stream >> message_length; - +template +inline T read_object(Socket& socket) { // TODO: Reuse buffers - std::vector buffer(message_length); - stream.read(buffer.data(), message_length); - return msgpack::unpack(buffer.data(), message_length).get().convert(); + // TODO: Use boost's buffers directly after switching to bitsery + char buffer[65536]; + auto message_length = socket.receive(boost::asio::buffer(buffer)); + + return msgpack::unpack(buffer, message_length).get().convert(); } diff --git a/src/plugin/bridge.cpp b/src/plugin/bridge.cpp index 0b69706a..7066377c 100644 --- a/src/plugin/bridge.cpp +++ b/src/plugin/bridge.cpp @@ -102,9 +102,9 @@ intptr_t Bridge::dispatch(AEffect* /*plugin*/, } const Event event{opcode, parameter, value, option}; - write_object(vst_stdin, event); + write_object(host_vst_dispatch, event); - const auto response = read_object(vst_stdout); + const auto response = read_object(host_vst_dispatch); if (response.result) { std::copy(response.result->begin(), response.result->end(), static_cast(result)); diff --git a/src/wine-host/vst-host.cpp b/src/wine-host/vst-host.cpp index c287f4ce..b57cccd1 100644 --- a/src/wine-host/vst-host.cpp +++ b/src/wine-host/vst-host.cpp @@ -86,7 +86,7 @@ int main(int argc, char* argv[]) { // TODO: Remove debug, we're just reporting the plugin's name we retrieved // above while (true) { - auto event = read_object(std::cin); + auto event = read_object(host_vst_dispatch); EventResult response; if (event.opcode == effGetEffectName) { @@ -96,7 +96,7 @@ int main(int argc, char* argv[]) { response.return_value = 0; } - write_object(std::cout, response); + write_object(host_vst_dispatch, response); } }