changeset 370:e0ea136144d7

Better resolution of loopback address. Should work on machines with mis-configured /etc/hosts.
author shade
date Thu, 23 Jan 2014 17:58:29 +0400
parents 1e5aee4ef63b
children 0d32511839fe
files jmh-core/src/main/java/org/openjdk/jmh/link/BinaryLinkServer.java
diffstat 1 files changed, 12 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/link/BinaryLinkServer.java	Thu Jan 23 17:01:24 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/link/BinaryLinkServer.java	Thu Jan 23 17:58:29 2014 +0400
@@ -157,11 +157,21 @@
             // shun
         }
 
-        // Otherwise fallback to well-known
+        // Otherwise open up the special loopback.
+        //   (It can only fail for the obscure reason)
+        try {
+            return InetAddress.getByAddress(new byte[] {127, 0, 0, 1});
+        } catch (UnknownHostException e) {
+            // shun
+        }
+
+        // Last resort. Open the local host: this resolves
+        // the machine name, and not reliable on mis-configured
+        // hosts, but there is nothing else we can try.
         try {
             return InetAddress.getLocalHost();
         } catch (UnknownHostException e) {
-            throw new IllegalStateException("Unable to resolve local host", e);
+            throw new IllegalStateException("Can not find the address to bind to.", e);
         }
     }