Skip to content

Commit

Permalink
reset peer on disconnect in enet::connected
Browse files Browse the repository at this point in the history
  • Loading branch information
jabuwu committed Aug 31, 2024
1 parent 2b189f7 commit 241be61
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 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.3
- Reset peer on connection error in `enet::connected`

# 0.3.2
- Fix a `Duration` underflow panic in `enet::connected`

Expand Down
9 changes: 4 additions & 5 deletions src/connected.rs
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,6 @@ impl<C: Connection> Host<C> {
let now = self.host.now();
let mut disconnect_event = None;
for peer in &mut self.peers {
let mut disconnect = false;
if let PeerState::AwaitingPeer { since, timeout, .. } = &mut peer.state {
if *since + *timeout < now {
peer.state = PeerState::Disconnected {
Expand Down Expand Up @@ -918,15 +917,14 @@ impl<C: Connection> Host<C> {
.write(address.clone(), (buffer[0..size]).to_vec());
}
Err(_) => {
disconnect = true;
peer.reset();
disconnect_event = Some(peer.id);
break;
}
_ => {}
}
}
}
if disconnect {
peer.disconnect(0);
}
}
if let Some(connection) = disconnect_event {
return Some(Event::Disconnect {
Expand Down Expand Up @@ -1153,6 +1151,7 @@ impl<C: Connection> Host<C> {
}

/// See [`Host::now`](`crate::Host::now`).
#[must_use]
pub fn now(&self) -> Duration {
self.host.now()
}
Expand Down

0 comments on commit 241be61

Please sign in to comment.