From b9315620e2dfae363ba4ddb88d14badc88bd5dee Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Thu, 22 Jun 2023 01:13:53 +0200 Subject: [PATCH] Fix adb forward initialization In forward mode, the dummy byte must be written immediately after the first accept(), otherwise the client will wait indefinitely, causing a deadlock (or a timeout). Regression introduced by 8c650e53cd37a53d5c3aa746c30a71c6b742a4e2. --- .../genymobile/scrcpy/DesktopConnection.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/DesktopConnection.java b/server/src/main/java/com/genymobile/scrcpy/DesktopConnection.java index 20ab1f9c..c3408fff 100644 --- a/server/src/main/java/com/genymobile/scrcpy/DesktopConnection.java +++ b/server/src/main/java/com/genymobile/scrcpy/DesktopConnection.java @@ -64,8 +64,6 @@ public final class DesktopConnection implements Closeable { throws IOException { String socketName = getSocketName(scid); - LocalSocket firstSocket = null; - LocalSocket videoSocket = null; LocalSocket audioSocket = null; LocalSocket controlSocket = null; @@ -74,24 +72,28 @@ public final class DesktopConnection implements Closeable { try (LocalServerSocket localServerSocket = new LocalServerSocket(socketName)) { if (video) { videoSocket = localServerSocket.accept(); - firstSocket = videoSocket; + if (sendDummyByte) { + // send one byte so the client may read() to detect a connection error + videoSocket.getOutputStream().write(0); + sendDummyByte = false; + } } if (audio) { audioSocket = localServerSocket.accept(); - if (firstSocket == null) { - firstSocket = audioSocket; + if (sendDummyByte) { + // send one byte so the client may read() to detect a connection error + audioSocket.getOutputStream().write(0); + sendDummyByte = false; } } if (control) { controlSocket = localServerSocket.accept(); - if (firstSocket == null) { - firstSocket = controlSocket; + if (sendDummyByte) { + // send one byte so the client may read() to detect a connection error + controlSocket.getOutputStream().write(0); + sendDummyByte = false; } } - if (sendDummyByte) { - // send one byte so the client may read() to detect a connection error - firstSocket.getOutputStream().write(0); - } } } else { if (video) {