Fixed ping timeout logic

Former-commit-id: 080ca9d4149ec0ecddd92c475d77e4fc92f6edaa
This commit is contained in:
Joshua Barretto 2019-03-06 13:51:01 +00:00
parent ffc4e6ebd4
commit 8a0adab381
2 changed files with 6 additions and 2 deletions

View File

@ -217,10 +217,11 @@ impl Client {
} }
} else if let Some(err) = self.postbox.error() { } else if let Some(err) = self.postbox.error() {
return Err(err.into()); return Err(err.into());
} else if self.state.get_time() - self.last_ping > SERVER_TIMEOUT * 0.5 {
self.postbox.send(ClientMsg::Ping);
} else if self.state.get_time() - self.last_ping > SERVER_TIMEOUT { } else if self.state.get_time() - self.last_ping > SERVER_TIMEOUT {
return Err(Error::ServerTimeout); return Err(Error::ServerTimeout);
} else if self.state.get_time() - self.last_ping > SERVER_TIMEOUT * 0.5 {
// Try pinging the server if the timeout is nearing
self.postbox.send(ClientMsg::Ping);
} }
Ok(frontend_events) Ok(frontend_events)

View File

@ -204,6 +204,9 @@ impl Server {
client.postbox.error().is_some() // Postbox error client.postbox.error().is_some() // Postbox error
{ {
disconnected = true; disconnected = true;
} else if state.get_time() - client.last_ping > CLIENT_TIMEOUT * 0.5 {
// Try pinging the client if the timeout is nearing
client.postbox.send(ServerMsg::Ping);
} }
if disconnected { if disconnected {