< prev index next >

src/jdk.net/linux/classes/jdk/internal/net/rdma/RdmaServerSocketChannelImpl.java

Print this page
rev 52804 : [mq]: nullBinding
rev 52801 : imported patch jdk12-8195160-version23.patch

@@ -25,10 +25,11 @@
 
 package jdk.internal.net.rdma;
 
 import java.io.FileDescriptor;
 import java.io.IOException;
+import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.ProtocolFamily;
 import java.net.ServerSocket;
 import java.net.SocketAddress;
 import java.net.SocketOption;

@@ -39,10 +40,11 @@
 import java.nio.channels.ClosedChannelException;
 import java.nio.channels.NotYetBoundException;
 import java.nio.channels.SelectionKey;
 import java.nio.channels.ServerSocketChannel;
 import java.nio.channels.SocketChannel;
+import java.nio.channels.UnsupportedAddressTypeException;
 import java.nio.channels.spi.SelectorProvider;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Objects;
 import java.util.Set;

@@ -52,10 +54,12 @@
 import sun.nio.ch.NativeThread;
 import sun.nio.ch.Net;
 import sun.nio.ch.SelChImpl;
 import sun.nio.ch.SelectionKeyImpl;
 import sun.net.ext.RdmaSocketOptions;
+import static java.net.StandardProtocolFamily.INET;
+import static java.net.StandardProtocolFamily.INET6;
 
 public class RdmaServerSocketChannelImpl
     extends ServerSocketChannel
     implements SelChImpl
 {

@@ -96,16 +100,15 @@
 
     RdmaServerSocketChannelImpl(SelectorProvider sp, ProtocolFamily family)
             throws IOException {
         super(checkSupported(sp));
         Objects.requireNonNull(family, "'family' is null");
-        if ((family != StandardProtocolFamily.INET) &&
-            (family != StandardProtocolFamily.INET6)) {
+        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");
             }
         }

@@ -192,19 +195,28 @@
 
     public final Set<SocketOption<?>> supportedOptions() {
         return DefaultOptionsHolder.defaultOptions;
     }
 
+    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 ServerSocketChannel bind(SocketAddress local, int backlog)
             throws IOException {
         synchronized (stateLock) {
             ensureOpen();
             if (localAddress != null)
                 throw new AlreadyBoundException();
             InetSocketAddress isa = (local == null)
-                                    ? new InetSocketAddress(0)
+                                    ? anyLocalAddress()
                                     : RdmaNet.checkAddress(local, family);
             SecurityManager sm = System.getSecurityManager();
             if (sm != null)
                 sm.checkListen(isa.getPort());
             RdmaNet.bind(family, fd, isa.getAddress(), isa.getPort());
< prev index next >