mirror of
https://github.com/uowuo/abaddon.git
synced 2026-08-15 05:19:58 +00:00
restart ra ws on timeout
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user