Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8242926

Add protocol specific factory creation methods to SocketChannel and ServerSocketChannel

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P3
    • Resolution: Approved
    • Fix Version/s: 15
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      source
    • Compatibility Risk:
      minimal
    • Compatibility Risk Description:
      These are new methods which do not affect existing behavior
    • Interface Kind:
      Java API
    • Scope:
      SE

      Description

      Summary

      Add static factory creation methods to java.nio.channels.SocketChannel and java.nio.channels.ServerSocketChannel which take a java.net.ProtocolFamily. These will allow channels to be created IPv4 only or IPv4/IPv6 regardless of the VM wide setting of the "java.net.preferIPv4Stack" system property. It will also facilitate the support of future non-IP protocol families as anticipated in JEP 380.

      Problem

      SocketChannel and ServerSocketChannel do not allow to specify a protocol family when opening a new channel. DatagramChannel has had this capability since Java 1.7. For consistency, it should be available for TCP sockets as well as UDP sockets.

      Solution

      The solution is straightforward and basically identical to that previously added to DatagramChannel, namely the addition of one new static factory method to SocketChannel and ServerSocketChannel, and the equivalent supporting methods to SelectorProvider.

      Specification

      Add the following new method to java.nio.channels.SocketChannel

      /**
       * Opens a socket channel. The {@code family} parameter specifies the
       * {@link ProtocolFamily protocol family} of the channel's socket.
       *
       * <p> The new channel is created by invoking the {@link
       * java.nio.channels.spi.SelectorProvider#openSocketChannel(ProtocolFamily)
       * openSocketChannel(ProtocolFamily)} method of the system-wide default.
       * {@link java.nio.channels.spi.SelectorProvider} object. </p>
       *
       * @param   family
       *          The protocol family
       *
       * @return  A new socket channel
       *
       * @throws  UnsupportedOperationException
       *          If the specified protocol family is not supported. For example,
       *          suppose the parameter is specified as {@link
       *          java.net.StandardProtocolFamily#INET6 StandardProtocolFamily.INET6}
       *          but IPv6 is not enabled on the platform.
       * @throws  IOException
       *          If an I/O error occurs
       *
       * @since 15
       */
      
      public static SocketChannel open(ProtocolFamily family) throws IOException {}

      Add the following new method to java.nio.channels.ServerSocketChannel

      /**
       * Opens a server-socket channel.The {@code family} parameter specifies the
       * {@link ProtocolFamily protocol family} of the channel's socket.
       *
       * <p> The new channel is created by invoking the {@link
       * java.nio.channels.spi.SelectorProvider#openServerSocketChannel(ProtocolFamily)
       * openServerSocketChannel(ProtocolFamily)} method of the system-wide default {@link
       * java.nio.channels.spi.SelectorProvider} object. </p>
       *
       * @param   family
       *          The protocol family
       *
       * @return  A new socket channel
       *
       * @throws  UnsupportedOperationException
       *          If the specified protocol family is not supported. For example,
       *          suppose the parameter is specified as {@link
       *          java.net.StandardProtocolFamily#INET6 StandardProtocolFamily.INET6}
       *          but IPv6 is not enabled on the platform.
       * @throws  IOException
       *          If an I/O error occurs
       *
       * @since 15
       */
      public static ServerSocketChannel open(ProtocolFamily family) throws IOException {}

      Add the following methods to java.nio.channels.spi.SelectorProvider

      /**
       * Opens a socket channel.
       *
       * @implSpec The default implementation of this method first checks that
       *          the given protocol {@code family} is not {@code null},
       *          then throws {@link UnsupportedOperationException}.
       *
       * @param   family
       *          The protocol family
       *
       * @return  The new channel
       *
       * @throws  UnsupportedOperationException
       *          If the specified protocol family is not supported
       * @throws  IOException
       *          If an I/O error occurs
       *
       * @since 15
       */
      public SocketChannel openSocketChannel(ProtocolFamily family) throws IOException {}
      
      /**
       * Opens a server-socket channel.
       *
       * @implSpec The default implementation of this method first checks that
       *          the given protocol {@code family} is not {@code null},
       *          then throws {@link UnsupportedOperationException}.
       *
       * @param   family
       *          The protocol family
       *
       * @return  The new channel
       *
       * @throws  UnsupportedOperationException
       *          If the specified protocol family is not supported
       * @throws  IOException
       *          If an I/O error occurs
       *
       * @since 15
       */
      public ServerSocketChannel openServerSocketChannel(ProtocolFamily family) throws IOException {}

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                michaelm Michael McMahon
                Reporter:
                michaelm Michael McMahon
                Reviewed By:
                Alan Bateman, Chris Hegarty, Daniel Fuchs
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: