Fix handling of large chunk data

This commit is contained in:
Robbert van der Helm
2020-04-27 16:41:55 +02:00
parent 527db1f49f
commit 13dcb2f74a
3 changed files with 16 additions and 7 deletions
-2
View File
@@ -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
+11 -4
View File
@@ -23,6 +23,8 @@
#include "../wine-host/boost-fix.h"
#endif
#include <boost/asio/local/stream_protocol.hpp>
#include <boost/asio/read.hpp>
#include <boost/asio/write.hpp>
template <typename B>
using OutputAdapter = bitsery::OutputBufferAdapter<B>;
@@ -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_t, 1>{size}));
socket.send(boost::asio::buffer(buffer, size));
boost::asio::write(socket,
boost::asio::buffer(std::array<size_t, 1>{size}));
boost::asio::write(socket, boost::asio::buffer(buffer, size));
}
/**
@@ -75,13 +78,17 @@ inline T& read_object(Socket& socket,
T& object,
std::vector<uint8_t> buffer = std::vector<uint8_t>(64)) {
std::array<size_t, 1> 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] =
+5 -1
View File
@@ -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&, bool>(logger, true), opcode, index,
value, data, option);