init chromium sdk 0.3.9-jb

This commit is contained in:
Vladimir Krivosheev
2013-04-16 13:09:42 +02:00
parent 3c05d08f93
commit 192fe2ada1
@@ -25,9 +25,7 @@ import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.UnknownHostException;
import java.net.*;
/**
* @author yole
@@ -38,6 +36,41 @@ public class NetUtils {
private NetUtils() {
}
public static boolean canConnectToSocket(String host, int port) {
if (host.equals("localhost") || host.equals("127.0.0.1")) {
try {
ServerSocket socket = new ServerSocket();
try {
//it looks like this flag should be set but it leads to incorrect results for NodeJS under Windows
//socket.setReuseAddress(true);
socket.bind(new InetSocketAddress(host, port));
}
finally {
try {
socket.close();
}
catch (IOException ignored) {
}
}
return false;
}
catch (IOException e) {
LOG.debug(e);
return true;
}
}
else {
try {
Socket socket = new Socket(host, port);
socket.close();
return true;
}
catch (IOException ignored) {
return false;
}
}
}
public static int findAvailableSocketPort() throws IOException {
final ServerSocket serverSocket = new ServerSocket(0);
try {