diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2021-05-22 23:43:16 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2021-05-22 23:43:16 +0300 |
commit | a2e133a11fc7e91f18bf23723a975bf69fb218db (patch) | |
tree | 127e52b610d5e4106d69f692e7444a537b1e61fd /src/server/server.cc | |
parent | 1c6fa70ab65e4b267b5163b18dd8743d3fdc8e8d (diff) |
server: add --device-error-limit
Diffstat (limited to 'src/server/server.cc')
-rw-r--r-- | src/server/server.cc | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/server/server.cc b/src/server/server.cc index c464b13..a025a7d 100644 --- a/src/server/server.cc +++ b/src/server/server.cc @@ -25,8 +25,10 @@ Server::Server(std::shared_ptr<voltronic::Device> device) : sock_(0) , port_(0) , cacheTimeout_(CACHE_TIMEOUT) - , delay_(0) + , delay_(DELAY) , endExecutionTime_(0) + , deviceErrorLimit_(DEVICE_ERROR_LIMIT) + , deviceErrorCounter_(0) , verbose_(false) , device_(std::move(device)) { client_.setDevice(device_); @@ -45,6 +47,10 @@ void Server::setDelay(u64 delay) { delay_ = delay; } +void Server::setDeviceErrorLimit(u32 deviceErrorLimit) { + deviceErrorLimit_ = deviceErrorLimit; +} + Server::~Server() { if (sock_ > 0) close(sock_); @@ -146,9 +152,13 @@ std::shared_ptr<p18::response_type::BaseResponse> Server::executeCommand(p18::Co }; cache_[commandType] = cr; + deviceErrorCounter_ = 0; return response; } catch (voltronic::DeviceError& e) { + deviceErrorCounter_++; + if (!shutdownCaught && deviceErrorCounter_ >= deviceErrorLimit_) + shutdownCaught = true; throw std::runtime_error("device error: " + std::string(e.what())); } catch (voltronic::TimeoutError& e) { |