From: Brian P. Hinz Date: Thu, 7 Nov 2019 00:24:16 +0000 (-0500) Subject: Set explicit connect timeout on socket and use timer instead of counting iterations X-Git-Tag: v1.10.90~93 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9de48d47ac6ca5974d5b7f2488cb68767371214c;p=tigervnc.git Set explicit connect timeout on socket and use timer instead of counting iterations --- 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) {