From b10bb9f8bfe0090c6a3da4070c1c8dc063f6ede5 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Wed, 1 Nov 2023 14:52:38 +0100 Subject: [PATCH] Shutdown connection before joining threads Interrupting async processors may require to shutdown the connection to wake up blocking calls. Therefore, shutdown the connection first, then join the threads, then close the connection. Refs commit 9c08eb79cb7941848882cb908cefee9933450de5 --- .../com/genymobile/scrcpy/DesktopConnection.java | 15 ++++++++++++--- .../main/java/com/genymobile/scrcpy/Server.java | 2 ++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/DesktopConnection.java b/server/src/main/java/com/genymobile/scrcpy/DesktopConnection.java index c3408fff..8bc743f8 100644 --- a/server/src/main/java/com/genymobile/scrcpy/DesktopConnection.java +++ b/server/src/main/java/com/genymobile/scrcpy/DesktopConnection.java @@ -132,20 +132,29 @@ public final class DesktopConnection implements Closeable { return controlSocket; } - public void close() throws IOException { + public void shutdown() throws IOException { if (videoSocket != null) { videoSocket.shutdownInput(); videoSocket.shutdownOutput(); - videoSocket.close(); } if (audioSocket != null) { audioSocket.shutdownInput(); audioSocket.shutdownOutput(); - audioSocket.close(); } if (controlSocket != null) { controlSocket.shutdownInput(); controlSocket.shutdownOutput(); + } + } + + public void close() throws IOException { + if (videoSocket != null) { + videoSocket.close(); + } + if (audioSocket != null) { + audioSocket.close(); + } + if (controlSocket != null) { controlSocket.close(); } } diff --git a/server/src/main/java/com/genymobile/scrcpy/Server.java b/server/src/main/java/com/genymobile/scrcpy/Server.java index 0126f396..a1c6090b 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Server.java +++ b/server/src/main/java/com/genymobile/scrcpy/Server.java @@ -163,6 +163,8 @@ public final class Server { asyncProcessor.stop(); } + connection.shutdown(); + try { initThread.join(); for (AsyncProcessor asyncProcessor : asyncProcessors) {