From 26e719eddcc0fb74d5cb3d66acf86f892369b777 Mon Sep 17 00:00:00 2001 From: Tipragot Date: Wed, 7 Feb 2024 16:10:59 +0000 Subject: [PATCH] Make an error when the connection is disconnected (#24) Reviewed-on: https://git.tipragot.fr/corentin/border-wars/pulls/24 Reviewed-by: Corentin Co-authored-by: Tipragot Co-committed-by: Tipragot --- crates/bevnet/src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/bevnet/src/lib.rs b/crates/bevnet/src/lib.rs index d78bc28..4b897cb 100644 --- a/crates/bevnet/src/lib.rs +++ b/crates/bevnet/src/lib.rs @@ -197,6 +197,12 @@ impl Connection { let receive_buffer = &mut self.receive_buffer[start_index..start_index + len]; let received_len = self.stream.read(receive_buffer); self.receive_filled_len += match received_len { + Ok(0) => { + return Err(io::Error::new( + io::ErrorKind::ConnectionAborted, + "connection closed by remote peer", + )); + } Ok(n) => n, Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => return Ok(false), Err(ref e) if e.kind() == io::ErrorKind::Interrupted => return Ok(false),