forked from M-Labs/nac3
1
0
Fork 0

comms: handle connection termination

This commit is contained in:
Astro 2020-05-01 02:09:00 +02:00
parent 895a3f47e2
commit 48025339b3
1 changed files with 9 additions and 2 deletions

View File

@ -107,8 +107,15 @@ async fn handle_connection(stream: &TcpStream, control: Rc<RefCell<kernel::Contr
expect(&stream, b"ARTIQ coredev\n").await?; expect(&stream, b"ARTIQ coredev\n").await?;
debug!("received connection"); debug!("received connection");
loop { loop {
if !expect(&stream, &[0x5a, 0x5a, 0x5a, 0x5a]).await? { match expect(&stream, &[0x5a, 0x5a, 0x5a, 0x5a]).await {
return Err(Error::UnexpectedPattern) Ok(true) => {}
Ok(false) =>
return Err(Error::UnexpectedPattern),
// peer has closed the connection
Err(smoltcp::Error::Illegal) =>
return Ok(()),
Err(e) =>
return Err(e)?,
} }
let request: Request = FromPrimitive::from_i8(read_i8(&stream).await?) let request: Request = FromPrimitive::from_i8(read_i8(&stream).await?)
.ok_or(Error::UnrecognizedPacket)?; .ok_or(Error::UnrecognizedPacket)?;