Skip to content

Commit

Permalink
make time_delta computation safer
Browse files Browse the repository at this point in the history
  • Loading branch information
eladyn committed Mar 22, 2023
1 parent 6ef29ae commit c1a3bfc
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions core/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,14 @@ impl Session {
match packet_type {
Some(Ping) => {
let server_timestamp = BigEndian::read_u32(data.as_ref()) as i64;
let timestamp = match SystemTime::now().duration_since(UNIX_EPOCH) {
Ok(dur) => dur,
Err(err) => err.duration(),
}
.as_secs() as i64;
let timestamp = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or(Duration::ZERO)
.as_secs() as i64;

{
let mut data = self.0.data.write();
data.time_delta = server_timestamp - timestamp;
data.time_delta = server_timestamp.saturating_sub(timestamp);
data.last_ping = Some(Instant::now());
}

Expand Down

0 comments on commit c1a3bfc

Please sign in to comment.