This commit is contained in:
2024-11-18 18:03:07 +03:00
parent 45b8d4a3c7
commit f3a6aa3571
3 changed files with 173 additions and 24 deletions

View File

@@ -252,14 +252,32 @@ public:
void start()
{
static bool first_time = true;
if (first_time) {
_serverPtr->logInfo("Start client session with ID = {} (addr = {}, thread = {})", _ident, (void*)this,
utils::AdcThisThreadId());
first_time = false;
}
_serverPtr->logInfo("Start client session with ID = {} (addr = {}, thread = {})", _ident, (void*)this,
utils::AdcThisThreadId());
do_start();
}
void stop()
{
_serverPtr->logInfo("Stop client session with ID = {} (addr = {}, thread = {})", _ident, (void*)this,
utils::AdcThisThreadId());
_netService.close();
}
protected:
netsession_ident_t _ident;
netservice_t _netService;
AdcDeviceNetServer* _serverPtr;
AdcDeviceNetServer::DeviceWrapper* _bindDevice;
std::chrono::milliseconds _recvTimeout = std::chrono::hours(12);
std::chrono::milliseconds _sendTimeout = std::chrono::seconds(5);
void do_start()
{
auto self(this->shared_from_this());
_netService.asyncReceive(
@@ -285,7 +303,7 @@ public:
netservice_t::formattableError(ec), (void*)this, utils::AdcThisThreadId());
stop();
} else {
start();
do_start();
}
},
_sendTimeout);
@@ -294,23 +312,6 @@ public:
_recvTimeout);
}
void stop()
{
_serverPtr->logInfo("Stop client session with ID = {} (addr = {}, thread = {})", _ident, (void*)this,
utils::AdcThisThreadId());
_netService.close();
}
protected:
netsession_ident_t _ident;
netservice_t _netService;
AdcDeviceNetServer* _serverPtr;
AdcDeviceNetServer::DeviceWrapper* _bindDevice;
std::chrono::milliseconds _recvTimeout = std::chrono::hours(12);
std::chrono::milliseconds _sendTimeout = std::chrono::seconds(5);
void processMessage(auto& msg)
{
typedef std::decay_t<decltype(msg)> msg_t;