mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-22 06:48:43 -06:00
better error handling on client
This commit is contained in:
parent
b8447bc121
commit
80ef55c8b3
|
@ -21,6 +21,7 @@ pub enum DisconnectReason {
|
|||
ClientDisconnected,
|
||||
KickedByServer(Option<String>),
|
||||
Timeout,
|
||||
ConnectionReset,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
|
@ -213,7 +214,16 @@ impl<S, R> Client<S, R> where S: Encode + Decode, R: Encode + Decode {
|
|||
}
|
||||
},
|
||||
Err(error) if error.kind() != ErrorKind::WouldBlock => {
|
||||
return Err(error.into());
|
||||
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,
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue