提交 d6e381f7 authored 作者: Thomas Mueller's avatar Thomas Mueller

Testing for local connections was very slow on some systems.

上级 6761c5c7
...@@ -155,15 +155,15 @@ public class NetUtils { ...@@ -155,15 +155,15 @@ public class NetUtils {
*/ */
public static boolean isLocalAddress(Socket socket) throws UnknownHostException { public static boolean isLocalAddress(Socket socket) throws UnknownHostException {
InetAddress test = socket.getInetAddress(); InetAddress test = socket.getInetAddress();
boolean result = true;
//## Java 1.4 begin ## //## Java 1.4 begin ##
result = test.isLoopbackAddress(); if (test.isLoopbackAddress()) {
if (result) { return true;
return result;
} }
//## Java 1.4 end ## //## Java 1.4 end ##
InetAddress localhost = InetAddress.getLocalHost(); InetAddress localhost = InetAddress.getLocalHost();
InetAddress[] list = InetAddress.getAllByName(localhost.getCanonicalHostName()); // localhost.getCanonicalHostName() is very very slow
String host = localhost.getHostAddress();
InetAddress[] list = InetAddress.getAllByName(host);
for (int i = 0; i < list.length; i++) { for (int i = 0; i < list.length; i++) {
InetAddress addr = list[i]; InetAddress addr = list[i];
if (test.equals(addr)) { if (test.equals(addr)) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论