1
0
Fork 0

close connections

This commit is contained in:
Sebastien Bourdeauducq 2020-04-17 14:43:14 +08:00
parent 6c18e24418
commit 1c67ff50e3
1 changed files with 4 additions and 2 deletions

View File

@ -141,7 +141,7 @@ async fn send_header(stream: &TcpStream, reply: Reply) -> Result<()> {
Ok(()) Ok(())
} }
async fn handle_connection(stream: TcpStream, control: Rc<RefCell<Option<kernel::Control>>>) -> Result<()> { async fn handle_connection(stream: &TcpStream, control: Rc<RefCell<kernel::Control>>) -> Result<()> {
expect(&stream, b"ARTIQ coredev\n").await?; expect(&stream, b"ARTIQ coredev\n").await?;
loop { loop {
expect(&stream, &[0x5a, 0x5a, 0x5a, 0x5a]).await?; expect(&stream, &[0x5a, 0x5a, 0x5a, 0x5a]).await?;
@ -224,9 +224,11 @@ pub fn main() {
while let stream = TcpStream::accept(1381, 2048, 2048).await.unwrap() { while let stream = TcpStream::accept(1381, 2048, 2048).await.unwrap() {
let control = control.clone(); let control = control.clone();
task::spawn(async { task::spawn(async {
let _ = handle_connection(stream, control) let _ = handle_connection(&stream, control)
.await .await
.map_err(|e| println!("Connection: {}", e)); .map_err(|e| println!("Connection: {}", e));
let _ = stream.flush().await;
let _ = stream.abort().await;
}); });
} }
} }