fix(event loop): handle UnexpectedEOF to remove client when disconnected
This commit is contained in:
@@ -61,12 +61,14 @@ impl EventLoop {
|
|||||||
token => loop {
|
token => loop {
|
||||||
match clients.get(token.0).unwrap().as_ref().unwrap().dispatch() {
|
match clients.get(token.0).unwrap().as_ref().unwrap().dispatch() {
|
||||||
Ok(_) => continue,
|
Ok(_) => continue,
|
||||||
Err(e) => {
|
Err(e) => match e.kind() {
|
||||||
if e.kind() == std::io::ErrorKind::WouldBlock {
|
std::io::ErrorKind::UnexpectedEof => {
|
||||||
|
clients.remove(token.0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return Err(e.into());
|
std::io::ErrorKind::WouldBlock => break,
|
||||||
}
|
_ => return Err(e.into()),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -86,11 +88,8 @@ impl Drop for EventLoop {
|
|||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
let buf: [u8; 1] = [1; 1];
|
let buf: [u8; 1] = [1; 1];
|
||||||
let _ = self.stop_write.write(buf.as_slice());
|
let _ = self.stop_write.write(buf.as_slice());
|
||||||
let _ = self
|
if let Some(handle) = self.join_handle.take() {
|
||||||
.join_handle
|
handle.join().unwrap().unwrap();
|
||||||
.take()
|
}
|
||||||
.and_then(|handle| handle.join().ok())
|
|
||||||
.as_ref()
|
|
||||||
.expect("Couldn't join the event loop thread at drop");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user