Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try-catch block added to KeepAliveThread::Run() #349

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 33 additions & 22 deletions src/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex> lock(Mutex);
std::cv_status status = Condition.wait_for(lock, std::chrono::milliseconds(t_sleep));
std::unique_lock<std::mutex> 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<uint8_t>(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<uint8_t>(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;
Expand Down
2 changes: 2 additions & 0 deletions src/core/model_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include <opc/ua/model.h>

#include <algorithm>

namespace OpcUa
{
namespace Model
Expand Down