From 13dcb2f74ac68388798f0e36c6d88a766ee80deb Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Mon, 27 Apr 2020 16:41:55 +0200 Subject: [PATCH] Fix handling of large chunk data --- README.md | 2 -- src/common/communication.h | 15 +++++++++++---- src/plugin/host-bridge.cpp | 6 +++++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e82843a7..913eeaa5 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,6 @@ There are a few things that should be done before releasing this, including: - Fix implementation bugs: - Phase Plant doesn't play any sound until the editor has been opened? - - Large chunk buffers can't be sent over the socket in one go, this causes - issues with presets that are multiple megabytes in size. - Serum crashed and audio engine froze while browsing through Serum presets in the browser? - KiloHearts plugins create a ridiculous amount of file descriptor leaks in diff --git a/src/common/communication.h b/src/common/communication.h index 46bc0528..1d1f5622 100644 --- a/src/common/communication.h +++ b/src/common/communication.h @@ -23,6 +23,8 @@ #include "../wine-host/boost-fix.h" #endif #include +#include +#include template using OutputAdapter = bitsery::OutputBufferAdapter; @@ -51,8 +53,9 @@ inline void write_object( // Tell the other side how large the object is so it can prepare a buffer // large enough before sending the data - socket.send(boost::asio::buffer(std::array{size})); - socket.send(boost::asio::buffer(buffer, size)); + boost::asio::write(socket, + boost::asio::buffer(std::array{size})); + boost::asio::write(socket, boost::asio::buffer(buffer, size)); } /** @@ -75,13 +78,17 @@ inline T& read_object(Socket& socket, T& object, std::vector buffer = std::vector(64)) { std::array message_length; - socket.receive(boost::asio::buffer(message_length)); + boost::asio::read(socket, boost::asio::buffer(message_length)); // Make sure the buffer is large enough const size_t size = message_length[0]; buffer.resize(size); - const auto actual_size = socket.receive(boost::asio::buffer(buffer)); + // `boost::asio::read/write` will handle all the packet splitting and + // merging for us, since local domain sockets have packet limits somewhere + // in the hundreds of kilobytes + const auto actual_size = + boost::asio::read(socket, boost::asio::buffer(buffer)); assert(size == actual_size); auto [_, success] = diff --git a/src/plugin/host-bridge.cpp b/src/plugin/host-bridge.cpp index 96724607..82f2d32f 100644 --- a/src/plugin/host-bridge.cpp +++ b/src/plugin/host-bridge.cpp @@ -353,7 +353,11 @@ intptr_t HostBridge::dispatch(AEffect* /*plugin*/, break; } - // TODO: Maybe reuse buffers here when dealing with chunk data + // We don't reuse any buffers here like we do for audio processing. This + // would be useful for chunk data, but since that's only needed when saving + // and loading plugin state it's much better to have bitsery or our + // receiving function temporarily allocate a large enough buffer rather than + // to have a bunch of allocated memory sitting around doing nothing. return send_event(host_vst_dispatch, dispatch_mutex, converter, std::pair(logger, true), opcode, index, value, data, option);