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:
Kacpherek committed 2026-10-28 05:59:37 +01:00
1 parent 56f968e11c
commit a5ee1e588c
1 file changed
+5 -3
+5 -3
View File
@@ -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 {