diff options
author | slewis | 2009-08-06 06:37:22 +0000 |
---|---|---|
committer | slewis | 2009-08-06 06:37:22 +0000 |
commit | 20b0e63ddd8913b7cc86ec34d31bac8954798262 (patch) | |
tree | 33ce3b4770ce403db925efd89f0eaec02b7d7b14 | |
parent | 43359632646dc4af0a0d5d952c481f2456458141 (diff) | |
download | org.eclipse.ecf-20b0e63ddd8913b7cc86ec34d31bac8954798262.tar.gz org.eclipse.ecf-20b0e63ddd8913b7cc86ec34d31bac8954798262.tar.xz org.eclipse.ecf-20b0e63ddd8913b7cc86ec34d31bac8954798262.zip |
Fix for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=285801 (remove unnecessary host name lookups)
-rw-r--r-- | server-side/bundles/org.eclipse.ecf.server.generic/src/org/eclipse/ecf/server/generic/app/Connector.java | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/server-side/bundles/org.eclipse.ecf.server.generic/src/org/eclipse/ecf/server/generic/app/Connector.java b/server-side/bundles/org.eclipse.ecf.server.generic/src/org/eclipse/ecf/server/generic/app/Connector.java index c15d5a263..47001e56b 100644 --- a/server-side/bundles/org.eclipse.ecf.server.generic/src/org/eclipse/ecf/server/generic/app/Connector.java +++ b/server-side/bundles/org.eclipse.ecf.server.generic/src/org/eclipse/ecf/server/generic/app/Connector.java @@ -9,10 +9,7 @@ package org.eclipse.ecf.server.generic.app; import java.net.InetAddress; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - +import java.util.*; import org.eclipse.ecf.provider.generic.TCPServerSOContainer; public class Connector { @@ -29,14 +26,13 @@ public class Connector { boolean discovery = false; List groups = new ArrayList(); - public Connector(String protocol, String host, int port, int timeout, - boolean discovery) { + public Connector(String protocol, String host, int port, int timeout, boolean discovery) { if (protocol != null && !protocol.equals(""))this.protocol = protocol; //$NON-NLS-1$ if (host != null && !host.equals(""))this.hostname = host; //$NON-NLS-1$ else { try { InetAddress addr = InetAddress.getLocalHost(); - this.hostname = addr.getCanonicalHostName(); + this.hostname = getHostNameForAddressWithoutLookup(addr); } catch (Exception e) { this.hostname = "localhost"; //$NON-NLS-1$ } @@ -46,6 +42,24 @@ public class Connector { this.discovery = discovery; } + private String getHostNameForAddressWithoutLookup(InetAddress inetAddress) { + // First get InetAddress.toString(), which returns + // the inet address in this form: "hostName/address". + // If hostname is not resolved the result is: "/address" + // So first we detect the location of the "/" to determine + // whether the host name is there or not + String inetAddressStr = inetAddress.toString(); + int slashPos = inetAddressStr.indexOf('/'); + if (slashPos == 0) + // no hostname is available so we strip + // off '/' and return address as string + return inetAddressStr.substring(1); + + // hostname is there/non-null, so we use it + return inetAddressStr.substring(0, slashPos); + + } + public Connector(String protocol, String host, int port, int timeout) { this(protocol, host, port, timeout, false); } |