diff options
author | Håkon Hallingstad <hakon@yahoo-inc.com> | 2017-02-20 17:13:18 +0100 |
---|---|---|
committer | Håkon Hallingstad <hakon@yahoo-inc.com> | 2017-02-20 17:13:18 +0100 |
commit | d27e86bcd396d64a92d4742083235ee6768dc6b9 (patch) | |
tree | f2daf9230f2575792e58f8abe76aeeeb8f8a0d86 /jrt/src | |
parent | 24eab4fe4b661526f327fcb32a045dfbc7f3c998 (diff) |
Makes clustercontroller-core work on WiFi
Diffstat (limited to 'jrt/src')
-rw-r--r-- | jrt/src/com/yahoo/jrt/Acceptor.java | 2 | ||||
-rw-r--r-- | jrt/src/com/yahoo/jrt/Connection.java | 2 | ||||
-rw-r--r-- | jrt/src/com/yahoo/jrt/Spec.java | 42 |
3 files changed, 37 insertions, 9 deletions
diff --git a/jrt/src/com/yahoo/jrt/Acceptor.java b/jrt/src/com/yahoo/jrt/Acceptor.java index 7316f8c620b..0f40c6c8e55 100644 --- a/jrt/src/com/yahoo/jrt/Acceptor.java +++ b/jrt/src/com/yahoo/jrt/Acceptor.java @@ -47,7 +47,7 @@ public class Acceptor { if (spec.port() != 0) { serverChannel.socket().setReuseAddress(true); } - serverChannel.socket().bind(spec.address(), 500); + serverChannel.socket().bind(spec.listenAddress(), 500); } catch (Exception e) { if (serverChannel != null) { try { serverChannel.socket().close(); } catch (Exception x) {} diff --git a/jrt/src/com/yahoo/jrt/Connection.java b/jrt/src/com/yahoo/jrt/Connection.java index 52964726eb7..24efdf46087 100644 --- a/jrt/src/com/yahoo/jrt/Connection.java +++ b/jrt/src/com/yahoo/jrt/Connection.java @@ -163,7 +163,7 @@ class Connection extends Target { return this; } try { - channel = SocketChannel.open(spec.address()); + channel = SocketChannel.open(spec.connectAddress()); } catch (Exception e) { setLostReason(e); } diff --git a/jrt/src/com/yahoo/jrt/Spec.java b/jrt/src/com/yahoo/jrt/Spec.java index 4c1f07b98a2..d40e773df68 100644 --- a/jrt/src/com/yahoo/jrt/Spec.java +++ b/jrt/src/com/yahoo/jrt/Spec.java @@ -4,8 +4,8 @@ package com.yahoo.jrt; import com.yahoo.net.HostName; -import java.net.SocketAddress; import java.net.InetSocketAddress; +import java.net.SocketAddress; /** @@ -70,6 +70,15 @@ public class Spec { } /** + * Creates a Spec with the hostname of the current/local host and given port + * + * @param port port number + */ + public static Spec fromLocalHostName(int port) { + return new Spec(HostName.getLocalhost(), port); + } + + /** * Obtain the host name of this address * * @return host name @@ -98,25 +107,44 @@ public class Spec { } /** - * Resolve the socket address for this Spec. If this Spec is + * Resolve the listening socket address for this Spec. If this Spec is + * malformed, this method will return null. + * + * @return listening socket address + */ + SocketAddress listenAddress() { + return address(host); + } + + /** + * Resolve the connect socket address for this Spec. If this Spec is * malformed, this method will return null. * - * @return socket address + * Why is this different than listenAddress()? If no host is given, a SocketAddress will be bound + * to the wildcard address (INADDR_ANY or 0.0.0.0 assuming IPv4) by InetSocketAddress. A wildcard + * address used to connect (at least SocketChannel::open) is interpreted as InetAddress::getLocalHost, + * which is wrong for the reasons stated in HostName::getLocalhost. + * + * @return connect socket address */ - SocketAddress address() { + SocketAddress connectAddress() { + return address(HostName.getLocalhost()); + } + + private SocketAddress address(String hostOverride) { if (malformed) { return null; } if (address == null) { - if (host == null) { + if (hostOverride == null) { address = new InetSocketAddress(port); } else { - address = new InetSocketAddress(host, port); + address = new InetSocketAddress(hostOverride, port); } } return address; } - + /** * Obtain a string representation of this address. The return * value from this method may be used to create a new Spec. |