--- old/src/jdk.net/linux/classes/jdk/internal/net/rdma/RdmaSocketChannelImpl.java 2018-12-04 19:57:59.191027398 +0000 +++ new/src/jdk.net/linux/classes/jdk/internal/net/rdma/RdmaSocketChannelImpl.java 2018-12-04 19:57:58.718791398 +0000 @@ -35,7 +35,6 @@ import java.net.Socket; import java.net.SocketAddress; import java.net.SocketOption; -import java.net.StandardProtocolFamily; import java.net.StandardSocketOptions; import java.nio.ByteBuffer; import java.nio.channels.AlreadyBoundException; @@ -47,6 +46,7 @@ import java.nio.channels.NotYetConnectedException; import java.nio.channels.SelectionKey; import java.nio.channels.SocketChannel; +import java.nio.channels.UnsupportedAddressTypeException; import java.nio.channels.spi.SelectorProvider; import java.util.Collections; import java.util.HashSet; @@ -56,10 +56,12 @@ import sun.net.ext.RdmaSocketOptions; import sun.nio.ch.IOStatus; import sun.nio.ch.IOUtil; -import sun.nio.ch.Net; import sun.nio.ch.NativeThread; +import sun.nio.ch.Net; import sun.nio.ch.SelChImpl; import sun.nio.ch.SelectionKeyImpl; +import static java.net.StandardProtocolFamily.INET; +import static java.net.StandardProtocolFamily.INET6; public class RdmaSocketChannelImpl extends SocketChannel @@ -67,7 +69,7 @@ { // The protocol family of the socket private final ProtocolFamily family; - + private static RdmaSocketDispatcher nd; private final FileDescriptor fd; private final int fdVal; @@ -103,7 +105,7 @@ private static final SelectorProvider checkSupported(SelectorProvider sp) { if (unsupported != null) throw new UnsupportedOperationException(unsupported.getMessage(), - unsupported); + unsupported); else return sp; } @@ -112,13 +114,11 @@ throws IOException { super(checkSupported(sp)); - Objects.requireNonNull(family, "'family' is null"); - if ((family != StandardProtocolFamily.INET) && - (family != StandardProtocolFamily.INET6)) { - throw new UnsupportedOperationException( - "Protocol family not supported"); + Objects.requireNonNull(family, "null family"); + if (!(family == INET || family == INET6)) { + throw new UnsupportedOperationException("Protocol family not supported"); } - if (family == StandardProtocolFamily.INET6) { + if (family == INET6) { if (!Net.isIPv6Available()) { throw new UnsupportedOperationException("IPv6 not available"); } @@ -129,12 +129,11 @@ this.fdVal = IOUtil.fdVal(fd); } - RdmaSocketChannelImpl(SelectorProvider sp, FileDescriptor fd, - InetSocketAddress isa) throws IOException { + RdmaSocketChannelImpl(SelectorProvider sp, + FileDescriptor fd, + InetSocketAddress isa) throws IOException { super(checkSupported(sp)); - this.family = Net.isIPv6Available() - ? StandardProtocolFamily.INET6 - : StandardProtocolFamily.INET; + this.family = Net.isIPv6Available() ? INET6 : INET; this.fd = fd; this.fdVal = IOUtil.fdVal(fd); synchronized (stateLock) { @@ -475,6 +474,15 @@ } } + private final InetSocketAddress anyLocalAddress() throws IOException { + if (family == INET) + return new InetSocketAddress(InetAddress.getByName("0.0.0.0"), 0); + else if (family == INET6) + return new InetSocketAddress(InetAddress.getByName("::"), 0); + else + throw new UnsupportedAddressTypeException(); + } + @Override public SocketChannel bind(SocketAddress local) throws IOException { readLock.lock(); @@ -487,9 +495,9 @@ throw new ConnectionPendingException(); if (localAddress != null) throw new AlreadyBoundException(); - InetSocketAddress isa = (local == null) ? - new InetSocketAddress(0) - : RdmaNet.checkAddress(local, family); + InetSocketAddress isa = (local == null) + ? anyLocalAddress() + : RdmaNet.checkAddress(local, family); SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkListen(isa.getPort());