Skip to content

Commit b931562

Browse files
committed
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 8c650e5.
1 parent ea59d52 commit b931562

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

server/src/main/java/com/genymobile/scrcpy/DesktopConnection.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ public static DesktopConnection open(int scid, boolean tunnelForward, boolean vi
6464
throws IOException {
6565
String socketName = getSocketName(scid);
6666

67-
LocalSocket firstSocket = null;
68-
6967
LocalSocket videoSocket = null;
7068
LocalSocket audioSocket = null;
7169
LocalSocket controlSocket = null;
@@ -74,24 +72,28 @@ public static DesktopConnection open(int scid, boolean tunnelForward, boolean vi
7472
try (LocalServerSocket localServerSocket = new LocalServerSocket(socketName)) {
7573
if (video) {
7674
videoSocket = localServerSocket.accept();
77-
firstSocket = videoSocket;
75+
if (sendDummyByte) {
76+
// send one byte so the client may read() to detect a connection error
77+
videoSocket.getOutputStream().write(0);
78+
sendDummyByte = false;
79+
}
7880
}
7981
if (audio) {
8082
audioSocket = localServerSocket.accept();
81-
if (firstSocket == null) {
82-
firstSocket = audioSocket;
83+
if (sendDummyByte) {
84+
// send one byte so the client may read() to detect a connection error
85+
audioSocket.getOutputStream().write(0);
86+
sendDummyByte = false;
8387
}
8488
}
8589
if (control) {
8690
controlSocket = localServerSocket.accept();
87-
if (firstSocket == null) {
88-
firstSocket = controlSocket;
91+
if (sendDummyByte) {
92+
// send one byte so the client may read() to detect a connection error
93+
controlSocket.getOutputStream().write(0);
94+
sendDummyByte = false;
8995
}
9096
}
91-
if (sendDummyByte) {
92-
// send one byte so the client may read() to detect a connection error
93-
firstSocket.getOutputStream().write(0);
94-
}
9597
}
9698
} else {
9799
if (video) {

0 commit comments

Comments
 (0)