Skip to content

Commit

Permalink
Fix adb forward initialization
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rom1v committed Jun 21, 2023
1 parent ea59d52 commit b931562
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions server/src/main/java/com/genymobile/scrcpy/DesktopConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ public static DesktopConnection open(int scid, boolean tunnelForward, boolean vi
throws IOException {
String socketName = getSocketName(scid);

LocalSocket firstSocket = null;

LocalSocket videoSocket = null;
LocalSocket audioSocket = null;
LocalSocket controlSocket = null;
Expand All @@ -74,24 +72,28 @@ public static DesktopConnection open(int scid, boolean tunnelForward, boolean vi
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) {
Expand Down

0 comments on commit b931562

Please sign in to comment.