From aaa219ce27561bfe060bee5a4eaba0326bc50412 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Sun, 9 Jul 2023 21:21:29 -0400 Subject: restart ra ws on timeout --- src/remoteauth/remoteauthclient.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/remoteauth/remoteauthclient.cpp') diff --git a/src/remoteauth/remoteauthclient.cpp b/src/remoteauth/remoteauthclient.cpp index c0a06d9..083bdaa 100644 --- a/src/remoteauth/remoteauthclient.cpp +++ b/src/remoteauth/remoteauthclient.cpp @@ -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(); 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; } -- cgit v1.2.3