File tree Expand file tree Collapse file tree
dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package datadog .trace .agent .test .utils ;
22
33import java .io .IOException ;
4+ import java .net .InetAddress ;
5+ import java .net .InetSocketAddress ;
46import java .net .ServerSocket ;
57import java .net .Socket ;
68import java .util .concurrent .TimeUnit ;
911public class PortUtils {
1012
1113 public static int UNUSABLE_PORT = 61 ;
14+ private static final int PORT_CONNECT_TIMEOUT_MS = 1000 ;
1215
1316 private static final int FREE_PORT_RANGE_START = 20000 ;
1417 private static final int FREE_PORT_RANGE_END = 40000 ;
@@ -96,7 +99,12 @@ private static boolean isPortOpen(final int port) {
9699 }
97100
98101 private static boolean isPortOpen (String host , int port ) {
99- try (final Socket socket = new Socket (host , port )) {
102+ try (final Socket socket = new Socket ()) {
103+ InetSocketAddress address =
104+ host == null
105+ ? new InetSocketAddress (InetAddress .getLoopbackAddress (), port )
106+ : new InetSocketAddress (host , port );
107+ socket .connect (address , PORT_CONNECT_TIMEOUT_MS );
100108 return true ;
101109 } catch (final IOException e ) {
102110 return false ;
You can’t perform that action at this time.
0 commit comments