< prev index next >

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

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

@@ -23,38 +23,33 @@
  * questions.
  */
 
 package jdk.internal.net.rdma;
 
+import java.io.FileDescriptor;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.io.FileDescriptor;
-import java.lang.reflect.Field;
-import java.net.InetAddress;
 import java.net.Inet4Address;
 import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
 import java.net.ProtocolFamily;
 import java.net.ServerSocket;
 import java.net.Socket;
+import java.net.SocketAddress;
+import java.net.SocketException;
 import java.net.SocketImpl;
 import java.net.SocketOption;
-import java.net.SocketException;
-import java.net.StandardProtocolFamily;
-import java.net.UnknownHostException;
-import java.net.InetAddress;
-import java.net.SocketAddress;
-import java.net.InetSocketAddress;
-import java.net.StandardSocketOptions;
 import java.net.SocketOptions;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
+import java.net.StandardSocketOptions;
+import java.net.UnknownHostException;
 import java.util.Objects;
 import java.util.Set;
 import sun.nio.ch.Net;
-import sun.net.ConnectionResetException;
-import sun.net.ext.RdmaSocketOptions;
+import static java.net.StandardProtocolFamily.INET;
+import static java.net.StandardProtocolFamily.INET6;
 
 public abstract class RdmaSocketImpl extends SocketImpl
 {
     private ProtocolFamily family;
 

@@ -120,28 +115,27 @@
             return null;
         }
     }
 
     public RdmaSocketImpl(ProtocolFamily family) {
-        this(checkSupported());
-        Objects.requireNonNull(family, "'family' is null");
-        if ((family != StandardProtocolFamily.INET) &&
-            (family != StandardProtocolFamily.INET6)) {
-            throw new UnsupportedOperationException(
-                    "Protocol family not supported");
+        this(checkSupported(), family);
+    }
+
+    private RdmaSocketImpl(Void unused, ProtocolFamily family) {
+        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");
             }
         }
         this.family = family;
     }
 
-    private RdmaSocketImpl(Void unused) { }
-
     private static volatile boolean checkedRdma;
     private static volatile boolean isRdmaAvailable;
 
     boolean isRdmaAvailable() {
         if (!checkedRdma) {

@@ -173,12 +167,11 @@
     protected synchronized void create(boolean stream) throws IOException {
         this.stream = stream;
         if (stream) {
             fd = new FileDescriptor();
 
-            boolean preferIPv6 = Net.isIPv6Available() &&
-                (family != StandardProtocolFamily.INET);
+            boolean preferIPv6 = Net.isIPv6Available() && (family != INET);
             rdmaSocketCreate(preferIPv6, true);
         }
     }
 
     protected void connect(String host, int port)

@@ -200,18 +193,14 @@
             }
         }
     }
 
     protected void connect(InetAddress address, int port) throws IOException {
-        if (family == StandardProtocolFamily.INET
-            && !(address instanceof Inet4Address))
-                throw new IllegalArgumentException(
-                        "address type not match");
-        if (family == StandardProtocolFamily.INET6
-            && !(address instanceof Inet6Address))
-                throw new IllegalArgumentException(
-                        "address type not match");
+        if (family == INET && !(address instanceof Inet4Address))
+                throw new IllegalArgumentException("address type mismatch");
+        if (family == INET6 && !(address instanceof Inet6Address))
+                throw new IllegalArgumentException("address type mismatch");
 
         this.port = port;
         this.address = address;
         try {
             connectToAddress(address, port, timeout);

@@ -228,18 +217,14 @@
         try {
             if (address == null || !(address instanceof InetSocketAddress))
                 throw new IllegalArgumentException("unsupported address type");
             InetSocketAddress addr = (InetSocketAddress) address;
             InetAddress ia = addr.getAddress();
-            if (family == StandardProtocolFamily.INET
-               && !(ia instanceof Inet4Address))
-                    throw new IllegalArgumentException(
-                            "address type not match");
-            if (family == StandardProtocolFamily.INET6
-                && !(ia instanceof Inet6Address))
-                    throw new IllegalArgumentException(
-                            "address type not match");
+            if (family == INET && !(ia instanceof Inet4Address))
+                throw new IllegalArgumentException("address type mismatch");
+            if (family == INET6 && !(ia instanceof Inet6Address))
+                throw new IllegalArgumentException("address type mismatch");
             if (addr.isUnresolved())
                 throw new UnknownHostException(addr.getHostName());
             this.port = addr.getPort();
             this.address = addr.getAddress();
 

@@ -370,12 +355,11 @@
 
     synchronized void doConnect(InetAddress address, int port, int timeout)
             throws IOException {
         try {
             acquireFD();
-            boolean preferIPv6 = Net.isIPv6Available() &&
-                (family != StandardProtocolFamily.INET);
+            boolean preferIPv6 = Net.isIPv6Available() && (family != INET);
             try {
                 rdmaSocketConnect(preferIPv6, address, port, timeout);
                 synchronized (fdLock) {
                     if (closePending) {
                         throw new SocketException ("Socket closed");

@@ -388,24 +372,32 @@
             close();
             throw e;
         }
     }
 
+    private final InetAddress anyLocalAddress() throws IOException {
+        if (family == INET)
+            return InetAddress.getByName("0.0.0.0");
+        else if (family == INET6)
+            return InetAddress.getByName("::");
+        else
+            throw new IllegalArgumentException("Unsupported address type " + family);
+    }
+
     protected synchronized void bind(InetAddress address, int lport)
             throws IOException {
         if (address == null)
             throw new IllegalArgumentException("address is null");
-        if (family == StandardProtocolFamily.INET
-            && !(address instanceof Inet4Address))
-                throw new IllegalArgumentException(
-                        "address type not match");
-        if (family == StandardProtocolFamily.INET6
-            && !(address instanceof Inet6Address))
-                throw new IllegalArgumentException(
-                        "address type not match");
-        boolean preferIPv6 = Net.isIPv6Available() &&
-            (family != StandardProtocolFamily.INET);
+
+        if (address.isAnyLocalAddress())
+            address = anyLocalAddress();
+
+        if (family == INET && !(address instanceof Inet4Address))
+            throw new IllegalArgumentException("address type mismatch");
+        if (family == INET6 && !(address instanceof Inet6Address))
+            throw new IllegalArgumentException("address type mismatch");
+        boolean preferIPv6 = Net.isIPv6Available() && (family != INET);
         rdmaSocketBind(preferIPv6, address, lport);
     }
 
     protected synchronized void listen(int count) throws IOException {
         rdmaSocketListen(count);
< prev index next >