From ad41cd6286f222c2ee37c1a5ec4f66e3b0596e69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Blin?= <sebastien.blin@savoirfairelinux.com> Date: Mon, 26 Oct 2020 14:21:47 -0400 Subject: [PATCH] mxsock: replace async by a thread and fix shutdown Change-Id: Ie5c14606c01c5c277b7939889eb035caa6607b52 --- src/jamidht/multiplexed_socket.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/jamidht/multiplexed_socket.cpp b/src/jamidht/multiplexed_socket.cpp index b2e512590c..3422b9a337 100644 --- a/src/jamidht/multiplexed_socket.cpp +++ b/src/jamidht/multiplexed_socket.cpp @@ -45,14 +45,13 @@ public: : parent_(parent) , deviceId(deviceId) , endpoint(std::move(endpoint)) - , eventLoopFut_ {std::async(std::launch::async, [this] { + , eventLoopThread_ {[this] { try { - stop.store(false); eventLoop(); } catch (const std::exception& e) { JAMI_ERR() << "[CNX] peer connection event loop failure: " << e.what(); } - })} + }} {} ~Impl() @@ -69,6 +68,7 @@ public: } sockets.clear(); } + eventLoopThread_.join(); } void shutdown() @@ -129,8 +129,8 @@ public: std::map<uint16_t, onChannelReadyCb> channelCbs {}; // Main loop to parse incoming packets - std::future<void> eventLoopFut_ {}; - std::atomic_bool stop {}; + std::atomic_bool stop {false}; + std::thread eventLoopThread_ {}; // Multiplexed available datas std::map<uint16_t, std::unique_ptr<ChannelInfo>> channelDatas_ {}; @@ -197,7 +197,7 @@ MultiplexedSocket::Impl::handleControlPacket(const std::vector<uint8_t>&& pkt) size_t off = 0; while (off != pkt.size()) { msgpack::unpacked result; - msgpack::unpack(result, (const char*)pkt.data(), pkt.size(), off); + msgpack::unpack(result, (const char*) pkt.data(), pkt.size(), off); auto req = result.get().as<ChannelRequest>(); if (req.state == ChannelRequestState::ACCEPT) { std::lock_guard<std::mutex> lkSockets(socketsMutex); -- GitLab