You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sj...@apache.org on 2014/12/19 13:28:06 UTC
[2/5] incubator-brooklyn git commit: Fix illegal argument in
isPortAvailable
Fix illegal argument in isPortAvailable
JRE docs say that the wildcard address can only be used on bind()
operations, but there's a case where we might use it in a connect()
call - this is undefined behaviour. Correct the code to pass in the
loopback address to connect() instead of the wildcard address.
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/25aaff93
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/25aaff93
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/25aaff93
Branch: refs/heads/master
Commit: 25aaff937a31f73a94f6caadb2fd6da303670f8b
Parents: 22e1c68
Author: Richard Downer <ri...@apache.org>
Authored: Thu Dec 18 14:02:57 2014 +0000
Committer: Richard Downer <ri...@apache.org>
Committed: Fri Dec 19 09:33:24 2014 +0000
----------------------------------------------------------------------
.../src/main/java/brooklyn/util/net/Networking.java | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/25aaff93/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 98fd828..77edb6f 100644
--- a/utils/common/src/main/java/brooklyn/util/net/Networking.java
+++ b/utils/common/src/main/java/brooklyn/util/net/Networking.java
@@ -78,12 +78,19 @@ public class Networking {
if (port < MIN_PORT_NUMBER || port > MAX_PORT_NUMBER) {
throw new IllegalArgumentException("Invalid start port: " + port);
}
+
+ // For some operations it's not valid to pass ANY_NIC (0.0.0.0).
+ // We substitute for the loopback address in those cases.
+ InetAddress localAddressNotAny = (localAddress==null || ANY_NIC.equals(localAddress))
+ ? LOOPBACK
+ : ANY_NIC;
+
Stopwatch watch = Stopwatch.createStarted();
try {
try {
Socket s = new Socket();
s.setSoTimeout(250);
- s.connect(new InetSocketAddress(localAddress, port), 250);
+ s.connect(new InetSocketAddress(localAddressNotAny, port), 250);
try {
s.close();
} catch (Exception e) {}
@@ -123,7 +130,8 @@ 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
+ // sometimes 0.0.0.0 can be bound to even if 127.0.0.1 has the port as in use;
+ // check all interfaces if 0.0.0.0 was requested
Enumeration<NetworkInterface> nis = null;
try {
nis = NetworkInterface.getNetworkInterfaces();