mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 22:34:27 +02:00
8241305: Add protocol specific factory creation methods to SocketChannel and ServerSocketChannel
Reviewed-by: alanb, chegar, dfuchs
This commit is contained in:
parent
42bad03de8
commit
0f7aeed416
12 changed files with 1044 additions and 33 deletions
|
@ -33,6 +33,7 @@ import java.net.SocketAddress;
|
|||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.spi.AbstractSelectableChannel;
|
||||
import java.nio.channels.spi.SelectorProvider;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
/**
|
||||
* A selectable channel for datagram-oriented sockets.
|
||||
|
@ -184,7 +185,7 @@ public abstract class DatagramChannel
|
|||
* @since 1.7
|
||||
*/
|
||||
public static DatagramChannel open(ProtocolFamily family) throws IOException {
|
||||
return SelectorProvider.provider().openDatagramChannel(family);
|
||||
return SelectorProvider.provider().openDatagramChannel(requireNonNull(family));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -26,11 +26,13 @@
|
|||
package java.nio.channels;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ProtocolFamily;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.SocketOption;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.channels.spi.AbstractSelectableChannel;
|
||||
import java.nio.channels.spi.SelectorProvider;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
/**
|
||||
* A selectable channel for stream-oriented listening sockets.
|
||||
|
@ -113,6 +115,34 @@ public abstract class ServerSocketChannel
|
|||
return SelectorProvider.provider().openServerSocketChannel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
return SelectorProvider.provider().openServerSocketChannel(requireNonNull(family));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an operation set identifying this channel's supported
|
||||
* operations.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -26,12 +26,14 @@
|
|||
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.nio.ByteBuffer;
|
||||
import java.nio.channels.spi.AbstractSelectableChannel;
|
||||
import java.nio.channels.spi.SelectorProvider;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
/**
|
||||
* A selectable channel for stream-oriented connecting sockets.
|
||||
|
@ -150,6 +152,34 @@ public abstract class SocketChannel
|
|||
return SelectorProvider.provider().openSocketChannel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
return SelectorProvider.provider().openSocketChannel(requireNonNull(family));
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a socket channel and connects it to a remote address.
|
||||
*
|
||||
|
|
|
@ -36,6 +36,7 @@ import java.nio.channels.SocketChannel;
|
|||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Iterator;
|
||||
import java.util.Objects;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.ServiceConfigurationError;
|
||||
|
||||
|
@ -315,4 +316,51 @@ public abstract class SelectorProvider {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
Objects.requireNonNull(family);
|
||||
throw new UnsupportedOperationException("Protocol family not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
Objects.requireNonNull(family);
|
||||
throw new UnsupportedOperationException("Protocol family not supported");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue