提交 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 {
*/
public static boolean isLocalAddress(Socket socket) throws UnknownHostException {
InetAddress test = socket.getInetAddress();
boolean result = true;
//## Java 1.4 begin ##
result = test.isLoopbackAddress();
if (result) {
return result;
if (test.isLoopbackAddress()) {
return true;
}
//## Java 1.4 end ##
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++) {
InetAddress addr = list[i];
if (test.equals(addr)) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论