...
This commit is contained in:
parent
d1d822415b
commit
a12c186bb3
@ -8,6 +8,7 @@ ABSTRACT DEVICE COMPONENTS LIBRARY
|
|||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <map>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
@ -159,6 +160,8 @@ protected:
|
|||||||
func() ? ++N : 0;
|
func() ? ++N : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_stopSessionFunc.clear();
|
||||||
|
|
||||||
return N;
|
return N;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -193,29 +196,48 @@ public:
|
|||||||
auto acceptor = std::make_shared<typename SessionT::netservice_t::acceptor_t>(
|
auto acceptor = std::make_shared<typename SessionT::netservice_t::acceptor_t>(
|
||||||
std::forward<AcceptorCtorArgTs>(ctor_args)...);
|
std::forward<AcceptorCtorArgTs>(ctor_args)...);
|
||||||
|
|
||||||
|
_stopListenFunc.emplace_back([acceptor, id, this]() {
|
||||||
|
std::error_code ec;
|
||||||
|
acceptor->close(ec);
|
||||||
|
|
||||||
|
_isListening<SessionT>[this][id] = false;
|
||||||
|
});
|
||||||
|
|
||||||
doAccept<SessionT>(acceptor, id, sess_ctx);
|
doAccept<SessionT>(acceptor, id, sess_ctx);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <interfaces::adc_netsession_c SessionT>
|
template <interfaces::adc_netsession_c SessionT>
|
||||||
bool isListening() const
|
bool isListening(const typename SessionT::netsession_ident_t& id) const
|
||||||
{
|
{
|
||||||
return _isListening<SessionT>[this];
|
return _isListening<SessionT>[this][id];
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void start() = 0;
|
virtual void start() = 0;
|
||||||
|
|
||||||
virtual void stop()
|
virtual void stop()
|
||||||
{
|
{
|
||||||
|
for (auto& func : _stopListenFunc) {
|
||||||
|
func();
|
||||||
|
}
|
||||||
|
|
||||||
|
_stopListenFunc.clear();
|
||||||
|
|
||||||
stopAllSessions();
|
stopAllSessions();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
// template <interfaces::adc_netsession_c SessionT>
|
||||||
|
// inline static std::unordered_map<const AdcGenericNetServer*, bool> _isListening{};
|
||||||
template <interfaces::adc_netsession_c SessionT>
|
template <interfaces::adc_netsession_c SessionT>
|
||||||
inline static std::unordered_map<const AdcGenericNetServer*, bool> _isListening{};
|
inline static std::unordered_map<const AdcGenericNetServer*,
|
||||||
|
std::map<const typename SessionT::netsession_ident_t, bool>>
|
||||||
|
_isListening{};
|
||||||
|
|
||||||
|
std::vector<std::function<void()>> _stopListenFunc;
|
||||||
|
|
||||||
server_ident_t _serverIdent;
|
server_ident_t _serverIdent;
|
||||||
|
|
||||||
@ -227,10 +249,10 @@ protected:
|
|||||||
auto sess = std::make_shared<SessionT>(id, std::move(srv), sess_ctx);
|
auto sess = std::make_shared<SessionT>(id, std::move(srv), sess_ctx);
|
||||||
startSession(sess);
|
startSession(sess);
|
||||||
|
|
||||||
_isListening<SessionT>[this] = true;
|
_isListening<SessionT>[this][id] = true;
|
||||||
doAccept(acceptor, id, sess_ctx);
|
doAccept(acceptor, id, sess_ctx);
|
||||||
} else {
|
} else {
|
||||||
_isListening<SessionT>[this] = false;
|
_isListening<SessionT>[this][id] = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user