diff --git a/src/client/client.cpp b/src/client/client.cpp index b6d35eae..4d4367e3 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -53,35 +53,46 @@ void KeepAliveThread::Run() while (!StopRequest) { - int64_t t_sleep = Period * 0.7; - LOG_DEBUG(Logger, "keep_alive_thread | sleeping for: {}ms", t_sleep); + try + { + int64_t t_sleep = Period * 0.7; + LOG_DEBUG(Logger, "keep_alive_thread | sleeping for: {}ms", t_sleep); - std::unique_lock lock(Mutex); - std::cv_status status = Condition.wait_for(lock, std::chrono::milliseconds(t_sleep)); + std::unique_lock lock(Mutex); + std::cv_status status = Condition.wait_for(lock, std::chrono::milliseconds(t_sleep)); - if (status == std::cv_status::no_timeout) - { - break; - } + if (status == std::cv_status::no_timeout) + { + break; + } - LOG_DEBUG(Logger, "keep_alive_thread | renewing secure channel"); + LOG_DEBUG(Logger, "keep_alive_thread | renewing secure channel"); - OpenSecureChannelParameters params; - params.ClientProtocolVersion = 0; - params.RequestType = SecurityTokenRequestType::Renew; - params.SecurityMode = MessageSecurityMode::None; - params.ClientNonce = std::vector(1, 0); - params.RequestLifeTime = Period; - OpenSecureChannelResponse response = Server->OpenSecureChannel(params); + OpenSecureChannelParameters params; + params.ClientProtocolVersion = 0; + params.RequestType = SecurityTokenRequestType::Renew; + params.SecurityMode = MessageSecurityMode::None; + params.ClientNonce = std::vector(1, 0); + params.RequestLifeTime = Period; + OpenSecureChannelResponse response = Server->OpenSecureChannel(params); - if ((response.ChannelSecurityToken.RevisedLifetime < Period) && (response.ChannelSecurityToken.RevisedLifetime > 0)) - { - Period = response.ChannelSecurityToken.RevisedLifetime; - } + if ((response.ChannelSecurityToken.RevisedLifetime < Period) && (response.ChannelSecurityToken.RevisedLifetime > 0)) + { + Period = response.ChannelSecurityToken.RevisedLifetime; + } - LOG_DEBUG(Logger, "keep_alive_thread | read a variable from address space to keep session open"); + LOG_DEBUG(Logger, "keep_alive_thread | read a variable from address space to keep session open"); - NodeToRead.GetValue(); + NodeToRead.GetValue(); + } + catch (const std::exception &e) + { + LOG_ERROR(Logger, "keep_alive_thread | error", e.what()); + } + catch (...) + { + LOG_ERROR(Logger, "keep_alive_thread | error unknown"); + } } Running = false; diff --git a/src/core/model_impl.h b/src/core/model_impl.h index 0f548c5a..84c75468 100644 --- a/src/core/model_impl.h +++ b/src/core/model_impl.h @@ -21,6 +21,8 @@ #include +#include + namespace OpcUa { namespace Model