From 143f54b9893f48da58c916c2087701cdf7501227 Mon Sep 17 00:00:00 2001 From: "Timur A. Fatkhullin" Date: Sun, 16 Jun 2024 22:18:15 +0300 Subject: [PATCH] ... --- net/adc_netserver.h | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/net/adc_netserver.h b/net/adc_netserver.h index 5f78e5f..4bb055a 100644 --- a/net/adc_netserver.h +++ b/net/adc_netserver.h @@ -7,6 +7,7 @@ ABSTRACT DEVICE COMPONENTS LIBRARY */ #include +#include #include #include @@ -262,12 +263,30 @@ protected: // started sessions waek pointers template static std::unordered_map> _serverSessions; + std::vector> _stopSessionFunc; template - void startAsyncSession(const typename SessionT::shared_ptr_t& sess_ptr) + void startSession(const typename SessionT::shared_ptr_t& sess_ptr) { - _serverSessions[this].insert(sess_ptr); - sess_ptr.start(); + auto res = _serverSessions[this].emplace(sess_ptr); + if (res.second) { + sess_ptr.start(); + + _stopSessionFunc.emplace_back([res]() { + if (!res.first.expired()) { // session is still existing + auto sess = res.first.lock(); + sess->stop(); + } + }); + } + } + + + void stopAllSessions() + { + for (auto& func : _stopSessionFunc) { + func(); + } } virtual void daemonizePrepare()