From c89b1e9e6e8d84d24e0bd3b36289be07e9e2a9f6 Mon Sep 17 00:00:00 2001 From: Jon Date: Thu, 16 Mar 2017 10:20:39 -0600 Subject: [PATCH 1/2] Use 4096 character buffers for MsgPack serialization. Using statically-sized buffers for dynamically-generated content is never the best solution, and we've run into a situation where we are consistently rubbing up against the initial 1024 character buffer size. Bumping it to 4096 for now seems to be sufficient, but a better solution would be to utilize a dynamically sized buffer, possibly via `std::string` so that memory management is handled implicitly. --- source/mpackCPP/MsgPack.h | 2 +- source/test/registerProcedureTest.cpp | 4 ++-- source/wamped/Wamp.cpp | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/source/mpackCPP/MsgPack.h b/source/mpackCPP/MsgPack.h index 87f20c4..d4b8e6f 100644 --- a/source/mpackCPP/MsgPack.h +++ b/source/mpackCPP/MsgPack.h @@ -28,7 +28,7 @@ class MsgPack { private: mpack_writer_t writer; - char data[1024]; + char data[4096]; void _getJson(std::stringstream &s, mpack_reader_t &reader) const; diff --git a/source/test/registerProcedureTest.cpp b/source/test/registerProcedureTest.cpp index a7bf451..99b1d10 100644 --- a/source/test/registerProcedureTest.cpp +++ b/source/test/registerProcedureTest.cpp @@ -13,7 +13,7 @@ // limitations under the License. #include "wamped/RegisteredProcedures.h" -#include "MsgPack.h" +#include "mpackCPP/MsgPack.h" #include #include @@ -53,4 +53,4 @@ int main() { if (p2->check(root)) std::cout << p2->invoke(root) << std::endl; -} \ No newline at end of file +} diff --git a/source/wamped/Wamp.cpp b/source/wamped/Wamp.cpp index 3655f42..c6c79d3 100644 --- a/source/wamped/Wamp.cpp +++ b/source/wamped/Wamp.cpp @@ -58,6 +58,7 @@ void Wamp::connect(std::function onJoin, std::function onError) } void Wamp::loggedSend(const std::string &msg) { + (void)msg; LOG("Sending " << msg << ": " << mp.getJson()); this->transport.sendMessage(mp.getData(), mp.getUsedBuffer()); } From 3ee83a2a61b5f09513d29717f2747a55a1e33123 Mon Sep 17 00:00:00 2001 From: Jon Date: Thu, 16 Mar 2017 20:58:28 -0500 Subject: [PATCH 2/2] Revert buffer size increase. There are some internals to the usage of the buffer that cause any change to it's size in `MsgPack.h` to result in a segfault. More research is needed to figure out where exactly the buffer gets used and whether its usage can be replaced by `mpack_writer_init_growable` for mostly-automatic memory management. --- source/mpackCPP/MsgPack.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/mpackCPP/MsgPack.h b/source/mpackCPP/MsgPack.h index d4b8e6f..87f20c4 100644 --- a/source/mpackCPP/MsgPack.h +++ b/source/mpackCPP/MsgPack.h @@ -28,7 +28,7 @@ class MsgPack { private: mpack_writer_t writer; - char data[4096]; + char data[1024]; void _getJson(std::stringstream &s, mpack_reader_t &reader) const;