1
0
Fork 0

use new smoltcp error code

This commit is contained in:
Sebastien Bourdeauducq 2021-05-29 17:13:22 +08:00
parent 0ae2138034
commit 21d98711c1
3 changed files with 4 additions and 4 deletions

View File

@ -94,13 +94,13 @@ async fn read_request(stream: &TcpStream, allow_close: bool) -> Result<Option<Re
Ok(true) => {}
Ok(false) =>
return Err(Error::UnexpectedPattern),
Err(smoltcp::Error::Illegal) => {
Err(smoltcp::Error::Finished) => {
if allow_close {
info!("peer closed connection");
return Ok(None);
} else {
error!("peer unexpectedly closed connection");
return Err(smoltcp::Error::Illegal)?;
return Err(smoltcp::Error::Finished)?;
}
},
Err(e) =>

View File

@ -121,7 +121,7 @@ async fn handle_connection(
loop {
let msg = read_i8(stream).await;
if let Err(smoltcp::Error::Illegal) = msg {
if let Err(smoltcp::Error::Finished) = msg {
return Ok(());
}
let msg: Request = FromPrimitive::from_i8(msg?).ok_or(Error::UnrecognizedPacket)?;

View File

@ -184,7 +184,7 @@ pub fn start(timer: GlobalTimer) {
info!("received connection");
let result = handle_connection(&stream, timer).await;
match result {
Err(Error::NetworkError(smoltcp::Error::Illegal)) => info!("peer closed connection"),
Err(Error::NetworkError(smoltcp::Error::Finished)) => info!("peer closed connection"),
Err(error) => warn!("connection terminated: {}", error),
_ => (),
}