in src/main/java/com/jetbrains/jdi/SocketTransportService.java [256:295]
public Connection attach(String address, long attachTimeout, long handshakeTimeout)
throws IOException {
if (address == null) {
throw new NullPointerException("address is null");
}
if (attachTimeout < 0 || handshakeTimeout < 0) {
throw new IllegalArgumentException("timeout is negative");
}
HostPort hostPort = HostPort.parse(address);
// open TCP connection to VM
// formally "*" is not correct hostname to attach
// but lets connect to localhost
InetSocketAddress sa = new InetSocketAddress(hostPort.host == null
? InetAddress.getLoopbackAddress().getHostAddress()
: hostPort.host, hostPort.port);
Socket s = new Socket();
try {
s.connect(sa, (int)attachTimeout);
} catch (SocketTimeoutException exc) {
try {
s.close();
} catch (IOException x) { }
throw new TransportTimeoutException("timed out trying to establish connection");
}
// handshake with the target VM
try {
handshake(s, handshakeTimeout);
} catch (IOException exc) {
try {
s.close();
} catch (IOException x) { }
throw exc;
}
return new SocketConnection(s);
}