add AdcGenericNetClient class
This commit is contained in:
@@ -371,7 +371,20 @@ public:
|
||||
};
|
||||
|
||||
|
||||
void setAcceptTimeout(const traits::adc_time_duration_c auto& timeout)
|
||||
{
|
||||
_acceptTimeout = std::chrono::duration_cast<decltype(_acceptTimeout)>(timeout);
|
||||
}
|
||||
|
||||
|
||||
auto getAcceptTimeout() const
|
||||
{
|
||||
return _acceptTimeout;
|
||||
}
|
||||
|
||||
|
||||
// helper methods for logging
|
||||
|
||||
template <traits::formattable... Ts>
|
||||
void logMessage(LoggerT::loglevel_t level, std::format_string<Ts...> fmt, Ts&&... args)
|
||||
{
|
||||
@@ -397,6 +410,8 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
std::chrono::seconds _acceptTimeout = std::chrono::seconds::max();
|
||||
|
||||
// template <interfaces::adc_netsession_c SessionT>
|
||||
// inline static std::unordered_map<const AdcGenericNetServer*, bool> _isListening{};
|
||||
template <interfaces::adc_netsession_c SessionT>
|
||||
@@ -412,24 +427,28 @@ protected:
|
||||
template <typename SessionT, typename AT, typename IDT, typename CTXT>
|
||||
void doAccept(std::shared_ptr<AT> acceptor, IDT id, CTXT sess_ctx)
|
||||
{
|
||||
acceptor->asyncAccept([acceptor, id = std::move(id), sess_ctx = std::move(sess_ctx), this](
|
||||
auto ec, typename SessionT::netservice_t srv) mutable {
|
||||
if (!ec) {
|
||||
logInfo(
|
||||
"Client connection is succesfully accepted! Client endpoint: {} (server addr = {}, thread = {})",
|
||||
srv.remoteEndpoint(), (void*)this, utils::AdcThisThreadId());
|
||||
acceptor->asyncAccept(
|
||||
[acceptor, id = std::move(id), sess_ctx = std::move(sess_ctx), this](
|
||||
auto ec, typename SessionT::netservice_t srv) mutable {
|
||||
if (!ec) {
|
||||
logInfo(
|
||||
"Client connection is succesfully accepted! Client endpoint: {} (server addr = {}, thread = "
|
||||
"{})",
|
||||
srv.remoteEndpoint(), (void*)this, utils::AdcThisThreadId());
|
||||
|
||||
auto sess = std::make_shared<SessionT>(id, std::move(srv), sess_ctx);
|
||||
startSession(sess);
|
||||
auto sess = std::make_shared<SessionT>(id, std::move(srv), sess_ctx);
|
||||
startSession(sess);
|
||||
|
||||
_isListening<SessionT>[this][id] = true;
|
||||
doAccept<SessionT>(acceptor, std::move(id), std::move(sess_ctx));
|
||||
} else {
|
||||
this->logError("Cannot start accepting connection: {}", SessionT::netservice_t::formattableError(ec));
|
||||
_isListening<SessionT>[this][id] = true;
|
||||
doAccept<SessionT>(acceptor, std::move(id), std::move(sess_ctx));
|
||||
} else {
|
||||
this->logError("Cannot start accepting connection: {}",
|
||||
SessionT::netservice_t::formattableError(ec));
|
||||
|
||||
_isListening<SessionT>[this][id] = false;
|
||||
}
|
||||
});
|
||||
_isListening<SessionT>[this][id] = false;
|
||||
}
|
||||
},
|
||||
_acceptTimeout);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user