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()