shutdown websocket if the server disconnected, level up the default log print

This commit is contained in:
Jovi Hsu 2021-11-17 14:42:08 +08:00
parent 694b462f60
commit f21a180053
3 changed files with 8 additions and 1 deletions

View File

@ -111,6 +111,9 @@ impl StreamHandler<Result<Bytes, io::Error>> for Agent {
}
Err(err) => {
error!("error: {:?}", err);
if self.ws_addr.is_some() {
self.ws_addr.as_ref().unwrap().do_send(ws::WsMsg::Close);
}
ctx.address().do_send(AgentMsg::Shutdown);
}
}

View File

@ -16,6 +16,7 @@ use super::agent::*;
#[rtype(result = "()")]
pub enum WsMsg {
SendToClient(Bytes),
Close,
}
/// Define Websocket actor
@ -41,6 +42,9 @@ impl Handler<WsMsg> for WsSession {
WsMsg::SendToClient(data) => {
ctx.binary(data);
}
WsMsg::Close => {
ctx.stop();
}
};
}
}

View File

@ -44,7 +44,7 @@ impl Default for AppData {
fn setup_logger() {
let logger = femme::pretty::Logger::new();
async_log::Logger::wrap(logger, || 12)
.start(log::LevelFilter::Trace)
.start(log::LevelFilter::Warn)
.unwrap();
}