...
This commit is contained in:
parent
3e8a113c3a
commit
143f54b989
@ -7,6 +7,7 @@ ABSTRACT DEVICE COMPONENTS LIBRARY
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <functional>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
@ -262,12 +263,30 @@ protected:
|
|||||||
// started sessions waek pointers
|
// started sessions waek pointers
|
||||||
template <traits::adc_netserver_session_c SessionT>
|
template <traits::adc_netserver_session_c SessionT>
|
||||||
static std::unordered_map<const AdcNetServer*, std::set<typename SessionT::weak_ptr_t>> _serverSessions;
|
static std::unordered_map<const AdcNetServer*, std::set<typename SessionT::weak_ptr_t>> _serverSessions;
|
||||||
|
std::vector<std::function<void()>> _stopSessionFunc;
|
||||||
|
|
||||||
template <traits::adc_netserver_session_c SessionT>
|
template <traits::adc_netserver_session_c SessionT>
|
||||||
void startAsyncSession(const typename SessionT::shared_ptr_t& sess_ptr)
|
void startSession(const typename SessionT::shared_ptr_t& sess_ptr)
|
||||||
{
|
{
|
||||||
_serverSessions<SessionT>[this].insert(sess_ptr);
|
auto res = _serverSessions<SessionT>[this].emplace(sess_ptr);
|
||||||
|
if (res.second) {
|
||||||
sess_ptr.start();
|
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()
|
virtual void daemonizePrepare()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user