< prev index next >

src/jdk.net/share/classes/jdk/net/Sockets.java

Print this page

        

@@ -24,16 +24,20 @@
  */
 
 package jdk.net;
 
 import java.net.*;
+import java.nio.channels.*;
 import java.io.IOException;
+import java.lang.reflect.Field;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
+import rdma.ch.RdmaPollSelectorProvider;
+import rdma.ch.RdmaSocketImpl;
 import jdk.net.ExtendedSocketOptions.PlatformSocketOptions;
 
 /**
  * Defines static methods to set and get socket options defined by the
  * {@link java.net.SocketOption} interface. All of the standard options defined

@@ -43,14 +47,25 @@
  * <p>
  * The {@link #supportedOptions(Class)} method can be called to determine
  * the complete set of options available (per socket type) on the
  * current system.
  * <p>
+ * The {@link #openRdmaSelector() openRdmaSelector}, {@link
+ * #openRdmaSocketChannel() openRdmaSocketChannel}, and {@link
+ * #openRdmaServerSocketChannel() openRdmaServerSocketChannel} methods
+ * create selectors and selectable channels for use with RDMA sockets.
+ * These objects are created a {@link java.nio.channels.spi.SelectorProvider
+ * SelectorProvider} that is not the default {@code SelectorProvider}.
+ * Consequently, selectable channels to RDMA sockets may not be multiplexed
+ * with selectable channel created by the default selector provider. The
+ * selector provider does not support datagram channels, its {@code
+ * openDatagramChannel} methods throw {@link UnsupportedOperationException}.
  * When a security manager is installed, some non-standard socket options
  * may require a security permission before being set or get.
  * The details are specified in {@link ExtendedSocketOptions}. No permission
  * is required for {@link java.net.StandardSocketOptions}.
+ * <p>
  *
  * @see java.nio.channels.NetworkChannel
  */
 public class Sockets {
 

@@ -373,6 +388,125 @@
             AVAILABLE = s.containsAll(Set.of(ExtendedSocketOptions.TCP_KEEPCOUNT,
                                             ExtendedSocketOptions.TCP_KEEPIDLE,
                                             ExtendedSocketOptions.TCP_KEEPINTERVAL));
         }
     }
+
+
+    /**
+     * Creates an unconnected RDMA socket.
+     *
+     * <p> A RDMA socket supports the same socket options that that {@code
+     * java.net.Socket} defines. In addition, it also supports the socket options
+     * specified by {@link RdmaSocketOptions}.
+     *
+     * @apiNote The rsocket implementation on Linux only supports IPv4 addresses.
+     * Consequently, attempting to bind or connect to an IPv6 address will fail
+     * with {@code IllegalArgumentException}.
+     *
+     * @throws IOException
+     *         If an I/O error occurs
+     * @throws UnsupportedOperationException
+     *         If RDMA sockets are not supported on this platform
+     *
+     * @since 12
+     */
+    public static Socket openRdmaSocket() throws IOException {
+        RdmaSocketImpl impl = new RdmaSocketImpl();
+        Socket s = new Socket(impl) {};
+        return s;
+    }
+
+    /**
+     * Creates an unbound RDMA server socket.
+     *
+     * <p> A RDMA socket supports the same socket options that that {@code
+     * java.net.ServerSocket} defines.
+     *
+     * @apiNote The rsocket implementation on Linux only supports IPv4 addresses.
+     * Consequently, attempting to bind to an IPv6 address will fail with
+     * {@code IllegalArgumentException}.
+     *
+     * @throws IOException
+     *         If an I/O error occurs
+     * @throws UnsupportedOperationException
+     *         If RDMA sockets are not supported on this platform
+     *
+     * @since N
+     */
+    public static ServerSocket openRdmaServerSocket() throws IOException {
+        SocketImpl impl = new RdmaSocketImpl();
+        ServerSocket ss = new ServerSocket(impl) {
+            public Socket accept() throws IOException {
+                if (isClosed())
+                throw new SocketException("Socket is closed");
+                if (!isBound())
+                    throw new SocketException("Socket is not bound yet");
+
+                Socket s = openRdmaSocket();
+                implAccept(s);
+                return s;
+            }    
+        };
+        return ss;
+    }
+
+    /**
+     * Opens a socket channel to a RDMA socket. A newly-created socket channel
+     * is {@link SocketChannel#isOpen() open}, not yet bound to a {@link
+     * SocketChannel#getLocalAddress() local address}, and not yet
+     * {@link SocketChannel#isConnected() connected}.
+     *
+     * <p> A socket channel to a RDMA socket supports all of the socket options
+     * specified by {@code SocketChannel}. In addition, it also supports the
+     * socket options specified by {@link RdmaSocketOptions}.
+     *
+     * @apiNote The rsocket implementation on Linux only supports IPv4 addresses.
+     * Consequently, attempting to bind or connect to an IPv6 address will fail
+     * with {@code UnsupportedAddressTypeException}.
+     *
+     * @throws IOException
+     *         If an I/O error occurs
+     * @throws UnsupportedOperationException
+     *         If RDMA sockets are not supported on this platform
+     *
+     * @since 12
+     */
+    public static SocketChannel openRdmaSocketChannel() throws IOException {
+        return RdmaPollSelectorProvider.provider().openSocketChannel();
+    }
+
+    /**
+     * Opens a server-socket channel to a RDMA socket. A newly-created socket
+     * channel is {@link SocketChannel#isOpen() open} but not yet bound to a
+     * {@link SocketChannel#getLocalAddress() local address}.
+     *
+     * @apiNote The rsocket implementation on Linux only supports IPv4 addresses.
+     * Consequently, attempting to bind to an IPv6 address will fail with
+     * {@code UnsupportedAddressTypeException}.
+     *
+     * @throws IOException
+     *         If an I/O error occurs
+     * @throws UnsupportedOperationException
+     *         If RDMA sockets are not supported on this platform
+     *
+     * @since 12
+     */
+    public static ServerSocketChannel openRdmaServerSocketChannel()
+        throws IOException {
+        return RdmaPollSelectorProvider.provider().openServerSocketChannel();
+    }
+ 
+    /**
+     * Opens a selector to multiplex selectable channels to RDMA sockets.
+     *
+     * @throws IOException
+     *         If an I/O error occurs
+     * @throws UnsupportedOperationException
+     *         If RDMA sockets are not supported on this platform
+     *
+     * @since 12
+     */
+    public static Selector openRdmaSelector() throws IOException {
+        return RdmaPollSelectorProvider.provider().openSelector();
+    }
 }
< prev index next >