diff --git a/net/adc_netserver.h b/net/adc_netserver.h index a138463..5d8a634 100644 --- a/net/adc_netserver.h +++ b/net/adc_netserver.h @@ -8,6 +8,7 @@ ABSTRACT DEVICE COMPONENTS LIBRARY #include #include +#include #include #include @@ -159,6 +160,8 @@ protected: func() ? ++N : 0; } + _stopSessionFunc.clear(); + return N; } }; @@ -193,29 +196,48 @@ public: auto acceptor = std::make_shared( std::forward(ctor_args)...); + _stopListenFunc.emplace_back([acceptor, id, this]() { + std::error_code ec; + acceptor->close(ec); + + _isListening[this][id] = false; + }); + doAccept(acceptor, id, sess_ctx); } }; template - bool isListening() const + bool isListening(const typename SessionT::netsession_ident_t& id) const { - return _isListening[this]; + return _isListening[this][id]; } virtual void start() = 0; virtual void stop() { + for (auto& func : _stopListenFunc) { + func(); + } + + _stopListenFunc.clear(); + stopAllSessions(); }; protected: + // template + // inline static std::unordered_map _isListening{}; template - inline static std::unordered_map _isListening{}; + inline static std::unordered_map> + _isListening{}; + + std::vector> _stopListenFunc; server_ident_t _serverIdent; @@ -227,10 +249,10 @@ protected: auto sess = std::make_shared(id, std::move(srv), sess_ctx); startSession(sess); - _isListening[this] = true; + _isListening[this][id] = true; doAccept(acceptor, id, sess_ctx); } else { - _isListening[this] = false; + _isListening[this][id] = false; } }); }