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,
|
ClientDisconnected,
|
||||||
KickedByServer(Option<String>),
|
KickedByServer(Option<String>),
|
||||||
Timeout,
|
Timeout,
|
||||||
|
ConnectionReset,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
#[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 => {
|
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,
|
_ => 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 => {
|
Err(error) if error.kind() != ErrorKind::WouldBlock => {
|
||||||
log::warn!("IO error {}", error);
|
log::error!("IO error {}", error);
|
||||||
// return Err(error.into());
|
// return Err(error.into());
|
||||||
},
|
},
|
||||||
_ => break,
|
_ => break,
|
||||||
|
|
|
@ -26,6 +26,7 @@ pub struct NetworkEvent(pub ClientEvent<ServerToClientMessage>);
|
||||||
pub fn create_client(
|
pub fn create_client(
|
||||||
storages: AllStoragesView
|
storages: AllStoragesView
|
||||||
) {
|
) {
|
||||||
|
log::info!("Creating client");
|
||||||
let address = storages.borrow::<UniqueView<ServerAddress>>().unwrap();
|
let address = storages.borrow::<UniqueView<ServerAddress>>().unwrap();
|
||||||
storages.add_unique(UdpClient(Client::new(
|
storages.add_unique(UdpClient(Client::new(
|
||||||
address.0,
|
address.0,
|
||||||
|
@ -37,7 +38,8 @@ pub fn create_client(
|
||||||
pub fn connect_client(
|
pub fn connect_client(
|
||||||
mut client: UniqueViewMut<UdpClient>
|
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();
|
client.0.connect().unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue