Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2009-08-06 06:43:40 +0000
committerslewis2009-08-06 06:43:40 +0000
commite9a6886aea3698fe8f58c261ec9453cec4f766c0 (patch)
treec23fb1154a39e9d4ae801049fbe6c8e1d4321295
parentd6b74898742939435bc384179846590815ec6627 (diff)
downloadorg.eclipse.ecf-e9a6886aea3698fe8f58c261ec9453cec4f766c0.tar.gz
org.eclipse.ecf-e9a6886aea3698fe8f58c261ec9453cec4f766c0.tar.xz
org.eclipse.ecf-e9a6886aea3698fe8f58c261ec9453cec4f766c0.zip
Fix for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=285801 (remove unnecessary host name lookups)
-rw-r--r--framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/Client.java22
1 files changed, 20 insertions, 2 deletions
diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/Client.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/Client.java
index 7ae7dcdbb..74fa1c3e8 100644
--- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/Client.java
+++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/Client.java
@@ -58,6 +58,24 @@ public final class Client implements ISynchAsynchConnection {
boolean disconnectHandled = false;
private final Object disconnectLock = new Object();
+ 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);
+
+ }
+
/**
* @param s
* @throws SocketException not thrown by this implementation.
@@ -66,7 +84,7 @@ public final class Client implements ISynchAsynchConnection {
socket = s;
if (s != null)
addressPort = s.getLocalPort() + ":" //$NON-NLS-1$
- + s.getInetAddress().getHostName() + ":" + s.getPort(); //$NON-NLS-1$
+ + getHostNameForAddressWithoutLookup(s.getInetAddress()) + ":" + s.getPort(); //$NON-NLS-1$
else
addressPort = "-1:<no endpoint>:-1"; //$NON-NLS-1$
}
@@ -105,7 +123,7 @@ public final class Client implements ISynchAsynchConnection {
return null;
ID retID = null;
try {
- retID = IDFactory.getDefault().createStringID(PROTOCOL + "://" + socket.getLocalAddress().getHostName() //$NON-NLS-1$
+ retID = IDFactory.getDefault().createStringID(PROTOCOL + "://" + getHostNameForAddressWithoutLookup(socket.getLocalAddress()) //$NON-NLS-1$
+ ":" + socket.getLocalPort()); //$NON-NLS-1$
} catch (final Exception e) {
traceStack("Exception in getLocalID()", e); //$NON-NLS-1$

Back to the top