Browse Source

disconnect a client if any error occurs

pull/127/head
jake 2 years ago
parent
commit
5b8f4fd087
  1. 21
      src/common/mainloop/client.rs

21
src/common/mainloop/client.rs

@ -1,5 +1,6 @@
use std::collections::HashMap;
use std::fmt::Debug;
use std::io::Write;
use async_std::channel;
use async_std::io::prelude::{ReadExt, WriteExt};
use async_std::sync::{Arc, RwLock};
@ -148,6 +149,26 @@ where
},
Err(err) => {
error!("[client recv {:?}] error {:?} ", client_id, err);
let mut f = std::fs::File::options().create(true).append(true).open("errors.txt").unwrap();
f.write_all(format!("[{client_id:?}] {err:?}").as_bytes()).unwrap();
// disconnect client on an error
for pkt in state.on_disconnect(client_id).await.unwrap() {
clients
.read()
.await
.get(&pkt.0)
.unwrap()
.send(pkt.1)
.await
.unwrap();
}
clients
.write()
.await
.remove(&client_id);
break;
}
}
}

Loading…
Cancel
Save