diff options
author | slewis | 2009-08-06 06:43:41 +0000 |
---|---|---|
committer | slewis | 2009-08-06 06:43:41 +0000 |
commit | 6d29f8a47ed1566cb62dff55961b8355e5dcbb68 (patch) | |
tree | 359d6fc1d7381887cf63cf285a3e9491dd6ca2f8 | |
parent | e9a6886aea3698fe8f58c261ec9453cec4f766c0 (diff) | |
download | org.eclipse.ecf-6d29f8a47ed1566cb62dff55961b8355e5dcbb68.tar.gz org.eclipse.ecf-6d29f8a47ed1566cb62dff55961b8355e5dcbb68.tar.xz org.eclipse.ecf-6d29f8a47ed1566cb62dff55961b8355e5dcbb68.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); } |