DectrisSimplonClient: separate connections for commands and status reads
Commands and configuration writes (initialize, disarm, threshold change) can take minutes. With one shared connection a status poll waited behind them; now commands/config writes go through one kept-alive client and status/config reads through another, each with its own mutex and fixed timeouts. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
9807bc40df
commit
41411b51b8
3 files changed
+46
-24
No files matched your search
@@ -21,8 +21,18 @@ std::string to_string(SimplonState state) {
|
||||
}
|
||||
|
||||
DectrisSimplonClient::DectrisSimplonClient(const std::string &addr, uint16_t in_port)
|
||||
: hostname(addr), port(in_port), http(std::make_unique<httplib::Client>(addr, in_port)) {
|
||||
http->set_keep_alive(true);
|
||||
: hostname(addr), port(in_port),
|
||||
cmd_http(std::make_unique<httplib::Client>(addr, in_port)),
|
||||
status_http(std::make_unique<httplib::Client>(addr, in_port)) {
|
||||
cmd_http->set_keep_alive(true);
|
||||
cmd_http->set_connection_timeout(std::chrono::seconds(1));
|
||||
cmd_http->set_read_timeout(std::chrono::minutes(20)); // Initialize or disarm might take a lot of time
|
||||
cmd_http->set_write_timeout(std::chrono::minutes(20)); // Initialize or disarm might take a lot of time
|
||||
|
||||
status_http->set_keep_alive(true);
|
||||
status_http->set_connection_timeout(std::chrono::milliseconds(500));
|
||||
status_http->set_read_timeout(std::chrono::seconds(1));
|
||||
status_http->set_write_timeout(std::chrono::seconds(1));
|
||||
}
|
||||
|
||||
DectrisSimplonClient::~DectrisSimplonClient() = default;
|
||||
@@ -48,12 +58,8 @@ void DectrisSimplonClient::SendDetectorCommand(SimplonDetectorCommand cmd) {
|
||||
}
|
||||
auto addr = GenAddr(SimplonModule::Detector, SimplonTask::Command, key);
|
||||
|
||||
std::lock_guard lg(http_mutex);
|
||||
http->set_connection_timeout(std::chrono::milliseconds(500));
|
||||
http->set_read_timeout(std::chrono::minutes(20)); // Initialize or disarm might take a lot of time
|
||||
http->set_write_timeout(std::chrono::minutes(20)); // Initialize or disarm might take a lot of time
|
||||
|
||||
auto res = http->Post(addr);
|
||||
std::lock_guard lg(cmd_mutex);
|
||||
auto res = cmd_http->Post(addr);
|
||||
|
||||
if (!res || res->status != httplib::StatusCode::OK_200) {
|
||||
std::string err_msg = "Command failed " + key;
|
||||
@@ -74,12 +80,8 @@ void DectrisSimplonClient::SetConfig(SimplonModule element, const std::string &k
|
||||
nlohmann::json j;
|
||||
j["value"] = value;
|
||||
|
||||
std::lock_guard lg(http_mutex);
|
||||
http->set_connection_timeout(std::chrono::seconds(1));
|
||||
http->set_read_timeout(std::chrono::minutes(20)); // Initialize or disarm might take a lot of time
|
||||
http->set_write_timeout(std::chrono::minutes(20)); // Initialize or disarm might take a lot of time
|
||||
|
||||
auto res = http->Post(addr, j.dump(), "application/json");
|
||||
std::lock_guard lg(cmd_mutex);
|
||||
auto res = cmd_http->Post(addr, j.dump(), "application/json");
|
||||
|
||||
if (!res || res->status != httplib::StatusCode::OK_200) {
|
||||
std::string err_msg = "Configure failed " + key;
|
||||
@@ -142,11 +144,8 @@ std::string DectrisSimplonClient::GenAddr(SimplonModule element, SimplonTask tas
|
||||
|
||||
SimplonConfig
|
||||
DectrisSimplonClient::GetConfig(SimplonModule element, SimplonTask task, const std::string &key) {
|
||||
std::lock_guard lg(http_mutex);
|
||||
http->set_connection_timeout(std::chrono::milliseconds(500));
|
||||
http->set_read_timeout(std::chrono::seconds(1));
|
||||
http->set_write_timeout(std::chrono::seconds(1));
|
||||
auto res = http->Get(GenAddr(element, task, key));
|
||||
std::lock_guard lg(status_mutex);
|
||||
auto res = status_http->Get(GenAddr(element, task, key));
|
||||
|
||||
if (!res) {
|
||||
throw JFJochException(JFJochExceptionCategory::SimplonError,
|
||||
|
||||
Reference in new issue
Block a user