Update network_manager.rs

this protects the network manager from crashing when a erroneous message is sent
This commit is contained in:
michael-bailey 2022-03-01 20:51:56 +00:00
parent 8f100c0f1c
commit e0b65fb520
1 changed files with 5 additions and 1 deletions

View File

@ -126,10 +126,14 @@ impl<Out: 'static> IManager for NetworkManager<Out>
{
async fn run(self: &Arc<Self>) {
let lock = self.listener.lock().await;
select! {
val = lock.accept() => {
if let Ok((stream, _addr)) = val {
let _ = self.handle_connection(Arc::new(stream.into())).await;
let conn = self.clone();
tokio::spawn(async move {
let _ = conn.handle_connection(Arc::new(stream.into())).await;
});
}
}
}