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?;
debug!("received connection");
loop {
if !expect(&stream, &[0x5a, 0x5a, 0x5a, 0x5a]).await? {
return Err(Error::UnexpectedPattern)
match expect(&stream, &[0x5a, 0x5a, 0x5a, 0x5a]).await {
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?)
.ok_or(Error::UnrecognizedPacket)?;