brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [03/16] git commit: when checking available port, if binding to all interfaces do an explicit check for localhost interface
Date Sun, 19 Oct 2014 00:59:50 GMT
when checking available port, if binding to all interfaces do an explicit check for localhost
interface


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/5861e2f6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/5861e2f6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/5861e2f6

Branch: refs/heads/master
Commit: 5861e2f6af082a2ce8366296f61e80a4c6ba9ed1
Parents: 6c196dc
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Mon Oct 6 22:30:22 2014 -0700
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Sat Oct 18 01:34:00 2014 +0100

----------------------------------------------------------------------
 .../src/main/java/brooklyn/util/net/Networking.java       | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/5861e2f6/utils/common/src/main/java/brooklyn/util/net/Networking.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/brooklyn/util/net/Networking.java b/utils/common/src/main/java/brooklyn/util/net/Networking.java
index 6b26463..98cdb85 100644
--- a/utils/common/src/main/java/brooklyn/util/net/Networking.java
+++ b/utils/common/src/main/java/brooklyn/util/net/Networking.java
@@ -100,7 +100,7 @@ public class Networking {
             ss.setReuseAddress(true);
             ds = new DatagramSocket(port);
             ds.setReuseAddress(true);
-            return true;
+            
         } catch (IOException e) {
             return false;
         } finally {
@@ -116,6 +116,14 @@ public class Networking {
                 }
             }
         }
+        
+        
+        if (localAddress==null || ANY_NIC.equals(localAddress)) {
+            // sometimes 0.0.0.0 can be bound to even if 127.0.0.1 has the port as in use;
check 127.0.0.1 if 0.0.0.0 was requested
+            return isPortAvailable(LOOPBACK, port);
+        }
+        
+        return true;
     }
     /** returns the first port available on the local machine >= the port supplied */
     public static int nextAvailablePort(int port) {


Mime
View raw message