mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-12-25 21:28:20 -06:00
better error handling on client
This commit is contained in:
parent
c9fcf889c3
commit
04d94383d0
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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