From 9de48d47ac6ca5974d5b7f2488cb68767371214c Mon Sep 17 00:00:00 2001 From: "Brian P. Hinz" Date: Wed, 6 Nov 2019 19:24:16 -0500 Subject: [PATCH] Set explicit connect timeout on socket and use timer instead of counting iterations --- java/com/tigervnc/vncviewer/Tunnel.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/java/com/tigervnc/vncviewer/Tunnel.java b/java/com/tigervnc/vncviewer/Tunnel.java index 2d0c61f5..ef5be279 100644 --- a/java/com/tigervnc/vncviewer/Tunnel.java +++ b/java/com/tigervnc/vncviewer/Tunnel.java @@ -212,7 +212,8 @@ public class Tunnel { Thread t = new Thread(new ExtProcess(cmd, vlog, true)); t.start(); // try for up to 5s - for (int i=0;i<50;i++) { + long start = System.currentTimeMillis(); + while (System.currentTimeMillis() - start < 5000) { if (isTunnelReady(localPort)) return; else @@ -232,7 +233,7 @@ public class Tunnel { java.net.Socket socket = new java.net.Socket(); boolean ready = false; try { - socket.connect(sockAddr); + socket.connect(sockAddr, 1000); ready = socket.isConnected(); socket.close(); } catch (IOException e) { -- 2.39.5