Make an error when the connection is disconnected (#24)
All checks were successful
Rust Checks / checks (push) Successful in 8s

Reviewed-on: corentin/border-wars#24
Reviewed-by: Corentin <solois.corentin@gmail.com>
Co-authored-by: Tipragot <contact@tipragot.fr>
Co-committed-by: Tipragot <contact@tipragot.fr>
This commit is contained in:
Tipragot 2024-02-07 16:10:59 +00:00 committed by Corentin
parent 2ca37c4ac0
commit 26e719eddc

View file

@ -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),