Skip to content

Commit

Permalink
fix a duration underflow
Browse files Browse the repository at this point in the history
  • Loading branch information
jabuwu committed Aug 16, 2024
1 parent 2401f15 commit abcbe91
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 0.3.2
- Fix a `Duration` underflow panic in `enet::connected`

# 0.3.1
- Add missing `enet::connected::Host::now` function

Expand Down
4 changes: 2 additions & 2 deletions src/connected.rs
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ impl<C: Connection> Host<C> {
for peer in &mut self.peers {
let mut disconnect = false;
if let PeerState::AwaitingPeer { since, timeout, .. } = &mut peer.state {
if *since < now - *timeout {
if *since + *timeout < now {
peer.state = PeerState::Disconnected {
last_peer_ptr: None,
};
Expand All @@ -887,7 +887,7 @@ impl<C: Connection> Host<C> {
..
} = &mut peer.state
{
if *last_send < now - Duration::from_secs(2) {
if *last_send + Duration::from_secs(2) < now {
peer.state = PeerState::Disconnected {
last_peer_ptr: last_peer_ptr.take(),
};
Expand Down

0 comments on commit abcbe91

Please sign in to comment.