< prev index next >

src/java.base/share/classes/java/nio/channels/SocketChannel.java

Print this page
rev 55750 : UDS support, temporary commit

@@ -24,13 +24,16 @@
  */
 
 package java.nio.channels;
 
 import java.io.IOException;
+import java.net.ProtocolFamily;
 import java.net.Socket;
 import java.net.SocketOption;
 import java.net.SocketAddress;
+import java.net.StandardProtocolFamily;
+import java.net.UnixSocketAddress;
 import java.nio.ByteBuffer;
 import java.nio.channels.spi.AbstractSelectableChannel;
 import java.nio.channels.spi.SelectorProvider;
 
 /**

@@ -149,10 +152,22 @@
     public static SocketChannel open() throws IOException {
         return SelectorProvider.provider().openSocketChannel();
     }
 
     /**
+     * Opens a socket channel for the specific address family.
+     *
+     * @see #open()
+     * @param family The protocol family e.g. AF_UNIX
+     * @return A new socket channel
+     * @throws IOException If an I/O error occurs
+     */
+    public static SocketChannel open(ProtocolFamily family) throws IOException {
+        return SelectorProvider.provider().openSocketChannel(family);
+    }
+
+    /**
      * Opens a socket channel and connects it to a remote address.
      *
      * <p> This convenience method works as if by invoking the {@link #open()}
      * method, invoking the {@link #connect(SocketAddress) connect} method upon
      * the resulting socket channel, passing it {@code remote}, and then

@@ -187,11 +202,11 @@
      *          If some other I/O error occurs
      */
     public static SocketChannel open(SocketAddress remote)
         throws IOException
     {
-        SocketChannel sc = open();
+        SocketChannel sc = remote instanceof UnixSocketAddress ? open(StandardProtocolFamily.UNIX) : open();
         try {
             sc.connect(remote);
         } catch (Throwable x) {
             try {
                 sc.close();
< prev index next >