restart ra ws on timeout

This commit is contained in:
ouwou
2023-07-09 21:21:29 -04:00
parent e0623281eb
commit aaa219ce27
4 changed files with 17 additions and 3 deletions

View File

@@ -34,6 +34,7 @@ void RemoteAuthClient::Stop() {
}
m_connected = false;
if (m_timeout_conn) m_timeout_conn.disconnect();
m_ws.Stop(1000);
m_heartbeat_waiter.kill();
if (m_heartbeat_thread.joinable()) m_heartbeat_thread.join();
@@ -44,6 +45,7 @@ bool RemoteAuthClient::IsConnected() const noexcept {
}
void RemoteAuthClient::OnGatewayMessage(const std::string &str) {
m_log->trace(str);
auto j = nlohmann::json::parse(str);
const auto opcode = j.at("op").get<std::string>();
if (opcode == "hello") {
@@ -67,6 +69,8 @@ void RemoteAuthClient::HandleGatewayHello(const nlohmann::json &j) {
m_heartbeat_msec = heartbeat_interval;
m_heartbeat_thread = std::thread(&RemoteAuthClient::HeartbeatThread, this);
m_timeout_conn = Glib::signal_timeout().connect(sigc::mem_fun(*this, &RemoteAuthClient::OnTimeout), timeout_ms);
Init();
m_signal_hello.emit();
@@ -294,6 +298,13 @@ void RemoteAuthClient::OnDispatch() {
OnGatewayMessage(msg);
}
bool RemoteAuthClient::OnTimeout() {
m_log->trace("Socket timeout");
Stop();
Start();
return false; // disconnect
}
RemoteAuthClient::type_signal_hello RemoteAuthClient::signal_hello() {
return m_signal_hello;
}