From 241be6153b9fe9ad1e514913821013b773e25c44 Mon Sep 17 00:00:00 2001 From: jabu Date: Sat, 31 Aug 2024 10:41:06 -0500 Subject: [PATCH] reset peer on disconnect in enet::connected --- CHANGELOG.md | 3 +++ src/connected.rs | 9 ++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1874119..ac4fa3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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` diff --git a/src/connected.rs b/src/connected.rs index c8879bb..8f6089c 100644 --- a/src/connected.rs +++ b/src/connected.rs @@ -871,7 +871,6 @@ impl Host { 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 { @@ -918,15 +917,14 @@ impl Host { .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 { @@ -1153,6 +1151,7 @@ impl Host { } /// See [`Host::now`](`crate::Host::now`). + #[must_use] pub fn now(&self) -> Duration { self.host.now() }