mirror of
https://github.com/horizon-rust/horizon.git
synced 2026-11-07 11:06:11 -10:00
Leave a server at once instead of waiting for the reader thread
On Windows a socket shutdown doesn't wake a read already waiting, so Disconnect froze the window until the server closed the connection. Vanilla closes the connection and moves on.
This commit is contained in:
1 parent
56f968e11c
commit
a5ee1e588c
1 file changed
+5
-3
@@ -262,13 +262,15 @@ impl Session {
|
||||
w.shutdown();
|
||||
}
|
||||
}
|
||||
/// `Connection.disconnect`: the socket closes and the game goes on at once.
|
||||
/// The reader thread is left to end on its own: on Windows a shutdown
|
||||
/// doesn't wake a read already waiting, so joining it held the window until
|
||||
/// the server dropped the connection, many seconds later.
|
||||
pub fn disconnect(&mut self) {
|
||||
if let Some(w) = self.writer.lock().unwrap().take() {
|
||||
w.shutdown();
|
||||
}
|
||||
if let Some(t) = self.thread.take() {
|
||||
let _ = t.join();
|
||||
}
|
||||
drop(self.thread.take());
|
||||
}
|
||||
}
|
||||
impl Drop for Session {
|
||||
|
||||
Reference in new issue
Block a user