better error handling on client

This commit is contained in:
griffi-gh 2023-02-12 22:28:44 +01:00
parent c9fcf889c3
commit 04d94383d0
3 changed files with 15 additions and 3 deletions

View file

@ -21,6 +21,7 @@ pub enum DisconnectReason {
ClientDisconnected,
KickedByServer(Option<String>),
Timeout,
ConnectionReset,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@ -213,8 +214,17 @@ impl<S, R> Client<S, R> where S: Encode + Decode, R: Encode + Decode {
}
},
Err(error) if error.kind() != ErrorKind::WouldBlock => {
match error.kind() {
ErrorKind::ConnectionReset => {
log::error!("Connection interrupted");
self.disconnect_inner(DisconnectReason::ConnectionReset, true)?;
},
_ => {
log::error!("IO error {error}");
return Err(error.into());
},
}
},
_ => break,
}
}

View file

@ -189,7 +189,7 @@ impl<S, R> Server<S, R> where S: Encode + Decode, R: Encode + Decode {
}
},
Err(error) if error.kind() != ErrorKind::WouldBlock => {
log::warn!("IO error {}", error);
log::error!("IO error {}", error);
// return Err(error.into());
},
_ => break,

View file

@ -26,6 +26,7 @@ pub struct NetworkEvent(pub ClientEvent<ServerToClientMessage>);
pub fn create_client(
storages: AllStoragesView
) {
log::info!("Creating client");
let address = storages.borrow::<UniqueView<ServerAddress>>().unwrap();
storages.add_unique(UdpClient(Client::new(
address.0,
@ -37,7 +38,8 @@ pub fn create_client(
pub fn connect_client(
mut client: UniqueViewMut<UdpClient>
) {
if !client.0.has_not_made_connection_attempts() {
if client.0.has_not_made_connection_attempts() {
log::info!("Connect called");
client.0.connect().unwrap();
}
}