Skip to content
Snippets Groups Projects
Commit 5a0a3803 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

mxsocket: parse message directly

technique from:
https://github.com/msgpack/msgpack-c/wiki/v1_1_cpp_unpacker#client-controls-a-buffer

Change-Id: I595e7b9eefdc396e6800cfa95ec299388c69e3e0
parent 35c6eab3
No related branches found
No related tags found
No related merge requests found
...@@ -193,15 +193,12 @@ MultiplexedSocket::Impl::handleControlPacket(const std::vector<uint8_t>&& pkt) ...@@ -193,15 +193,12 @@ MultiplexedSocket::Impl::handleControlPacket(const std::vector<uint8_t>&& pkt)
{ {
// Run this on dedicated thread because some callbacks can take time // Run this on dedicated thread because some callbacks can take time
dht::ThreadPool::io().run([this, pkt = std::move(pkt)]() { dht::ThreadPool::io().run([this, pkt = std::move(pkt)]() {
msgpack::unpacker pac;
pac.reserve_buffer(pkt.size());
memcpy(pac.buffer(), pkt.data(), pkt.size());
pac.buffer_consumed(pkt.size());
msgpack::object_handle oh;
while (pac.next(oh)) {
try { try {
auto req = oh.get().as<ChannelRequest>(); size_t off = 0;
while (off != pkt.size()) {
msgpack::unpacked result;
msgpack::unpack(result, (const char*)pkt.data(), pkt.size(), off);
auto req = result.get().as<ChannelRequest>();
if (req.state == ChannelRequestState::ACCEPT) { if (req.state == ChannelRequestState::ACCEPT) {
std::lock_guard<std::mutex> lkSockets(socketsMutex); std::lock_guard<std::mutex> lkSockets(socketsMutex);
auto& channel = channelDatas_[req.channel]; auto& channel = channelDatas_[req.channel];
...@@ -272,11 +269,11 @@ MultiplexedSocket::Impl::handleControlPacket(const std::vector<uint8_t>&& pkt) ...@@ -272,11 +269,11 @@ MultiplexedSocket::Impl::handleControlPacket(const std::vector<uint8_t>&& pkt)
} }
} }
} }
}
} catch (const std::exception& e) { } catch (const std::exception& e) {
JAMI_ERR("Error on the control channel: %s", e.what()); JAMI_ERR("Error on the control channel: %s", e.what());
stop.store(true); stop.store(true);
} }
}
}); });
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment