# HG changeset patch # User michaelm # Date 1573206415 0 # Node ID 5c79956cc7d7a5b5d42a6bf460b97c18ddeeda69 # Parent aca099f4b3ec16ce360a29fe84631b169b85a1fa Minor updates to spec, and fix test issues diff -r aca099f4b3ec -r 5c79956cc7d7 src/java.base/share/classes/java/nio/channels/ServerSocketChannel.java --- a/src/java.base/share/classes/java/nio/channels/ServerSocketChannel.java Tue Nov 05 18:34:02 2019 +0000 +++ b/src/java.base/share/classes/java/nio/channels/ServerSocketChannel.java Fri Nov 08 09:46:55 2019 +0000 @@ -37,7 +37,7 @@ /** * A selectable channel for stream-oriented listening sockets. * - *

A server-socket channel is created by invoking the open methods of this class. + *

A server-socket channel is created by invoking one of the open methods of this class. * It is not possible to create a channel for an arbitrary, * pre-existing {@link ServerSocket}. A newly-created server-socket channel is * open but not yet bound. An attempt to invoke the {@link #accept() accept} @@ -46,11 +46,11 @@ * {@link #bind(java.net.SocketAddress,int) bind} methods defined by this class. * *

Two kinds of server-socket channel are supported: IP (Internet Protocol) - * and unix domain depending on which open method is used to create them and which subtype of + * and Unix Domain depending on which open method is used to create them and which subtype of * {@link SocketAddress} that they support for local and remote addresses. * IP channels are created using {@link #open()}. They use {@link * InetSocketAddress} addresses and support both IPv4 and IPv6 TCP/IP. - * unix domain channels are created using {@link #open(ProtocolFamily)} + * Unix Domain channels are created using {@link #open(ProtocolFamily)} * with the family parameter set to {@link StandardProtocolFamily#UNIX}. * They use {@link UnixDomainSocketAddress}es and also * do not support the {@link #socket()} method. @@ -84,7 +84,7 @@ *

Server-socket channels are safe for use by multiple concurrent threads. *

* - *

Unix domain server-socket channels support a subset of the options listed above. + *

Unix Domain server-socket channels support a subset of the options listed above. * * @author Mark Reinhold * @author JSR-51 Expert Group @@ -186,7 +186,7 @@ * @throws SecurityException * If a security manager has been installed and its * {@link SecurityManager#checkListen checkListen} method denies - * the operation for IP channels. Or with unix domain + * the operation for IP channels. Or with Unix Domain * channels, if the security manager denies "read" or "write" * {@link java.io.FilePermission} for the local path. * @@ -213,7 +213,7 @@ * the value {@code 0}, or a negative value, then an implementation specific * default is used. * - *

Note, for Unix domain channels, a file is created in the file-system + *

Note, for Unix Domain channels, a file is created in the file-system * with the same path name as this channel's bound {@link UnixDomainSocketAddress}. * This file persists after the channel is closed, and must be removed before * another channel can bind to the same name. @@ -237,7 +237,7 @@ * @throws SecurityException * If a security manager has been installed and its * {@link SecurityManager#checkListen checkListen} method denies - * the operation for IP channels. Or with unix domain + * the operation for IP channels; or in the case of Unix Domain * channels, if the security manager denies "read" or "write" * {@link java.io.FilePermission} for the local path. * @@ -259,13 +259,14 @@ /** * Retrieves a server socket associated with this channel if it is an IP - * channel. The operation is not supported for unix domain channels. + * channel. The operation is not supported for Unix Domain channels. * *

The returned object will not declare any public methods that are not * declared in the {@link java.net.ServerSocket} class.

* * @return A server socket associated with this channel - * @throws UnsupportedOperationException if this is a Unix domain channel + * + * @throws UnsupportedOperationException if this is a Unix Domain channel */ public abstract ServerSocket socket(); @@ -288,7 +289,7 @@ * permitted by the security manager's {@link * java.lang.SecurityManager#checkAccept checkAccept} method.

* - *

For unix domain channels, this method performs a security + *

For Unix Domain channels, this method performs a security * manager {@link SecurityManager#checkPermission(Permission)} using * a {@link java.io.FilePermission} constructed with the path from the * remote address and "read,write" as the actions. @@ -325,8 +326,8 @@ /** * {@inheritDoc} - * Where the channel is bound to a Unix domain address, the return - * value from this this method is of type {@link UnixDomainSocketAddress}. + * Where the channel is bound to a Unix Domain address, the return + * value from this method is of type {@link UnixDomainSocketAddress}. *

* If there is a security manager set and this is an IP channel, * {@code checkConnect} method is @@ -336,7 +337,7 @@ * {@link java.net.InetAddress#getLoopbackAddress loopback} address and the * local port of the channel's socket is returned. *

- * If there is a security manager set and this is a unix domain channel, + * If there is a security manager set and this is a Unix Domain channel, * then {@link SecurityManager#checkPermission(Permission)} is called using * a {@link java.io.FilePermission} constructed with the path from the * local address and "read" as the action. If this check fails @@ -344,8 +345,8 @@ * is returned. * * @return The {@code SocketAddress} that the socket is bound to, or the - * {@code SocketAddress} representing the loopback address if - * denied by the security manager, or {@code null} if the + * {@code SocketAddress} representing the loopback address or empty + * pathname if denied by the security manager, or {@code null} if the * channel's socket is not bound * * @throws ClosedChannelException {@inheritDoc} diff -r aca099f4b3ec -r 5c79956cc7d7 src/java.base/share/classes/java/nio/channels/SocketChannel.java --- a/src/java.base/share/classes/java/nio/channels/SocketChannel.java Tue Nov 05 18:34:02 2019 +0000 +++ b/src/java.base/share/classes/java/nio/channels/SocketChannel.java Fri Nov 08 09:46:55 2019 +0000 @@ -67,14 +67,16 @@ * AsynchronousCloseException}. * *

Two kinds of socket channel are supported: IP (Internet Protocol) and - * unix domain depending on which open method is used to create them and which + * Unix Domain depending on which open method is used to create them and which * subtype of {@link SocketAddress} that they support for local and remote addresses. * IP channels are created using {@link #open()}. They use {@link * InetSocketAddress} addresses and support both IPv4 and IPv6 TCP/IP. - * unix domain channels are created using {@link #open(ProtocolFamily)} + * Unix Domain channels are created using {@link #open(ProtocolFamily)} * with the family parameter set to {@link StandardProtocolFamily#UNIX}. * They use {@link UnixDomainSocketAddress}es and also - * do not support the {@link #socket()} method. + * do not support the {@link #socket()} method. Note, it is also possible to + * create channels that support either IPv4 or IPv6 only through the + * {@link #open(ProtocolFamily)} method. * *

Socket options are configured using the {@link #setOption(SocketOption,Object) * setOption} method. IP socket channels support the following options: @@ -126,7 +128,7 @@ * or write operation while an invocation of one of these methods is in * progress will block until that invocation is complete.

* - *

Unix domain channels support a subset of the options listed above. + *

Unix Domain channels support a subset of the options listed above. * * @author Mark Reinhold * @author JSR-51 Expert Group @@ -183,18 +185,18 @@ /** * Opens a socket channel and connects it to a remote address. * Depending on the type of {@link SocketAddress} supplied, the returned object - * is an IP or unix domain channel. + * is an IP or Unix Domain channel. * *

For {@link InetSocketAddress}es 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 - * returning that channel.

+ * the resulting socket channel, passing it {@code remote}, which must be an + * {@link InetSocketAddress} and then returning that channel.

* *

For {@link UnixDomainSocketAddress}es it works as if by invoking the {@link * #open(ProtocolFamily)} method with {@link StandardProtocolFamily#UNIX} as parameter, * invoking the {@link #connect(SocketAddress) connect} method upon - * the resulting socket channel, passing it {@code remote}, and then - * returning that channel.

+ * the resulting socket channel, passing it {@code remote}, which must be a + * {@link UnixDomainSocketAddress} and then returning that channel.

* * @param remote * The remote address to which the new channel is to be connected @@ -272,7 +274,7 @@ /** * {@inheritDoc} * - *

Note, for Unix domain channels, a file is created in the file-system + *

Note, for Unix Domain channels, a file is created in the file-system * with the same name as this channel's bound address. This file persists after * the channel is closed, and must be removed before another channel can bind * to the same name. @@ -287,7 +289,7 @@ * @throws SecurityException * If a security manager has been installed and its * {@link SecurityManager#checkListen checkListen} method denies - * the operation for IP channels or for unix domain + * the operation for IP channels; or for Unix Domain * channels, if the security manager denies "read" or "write" * {@link java.io.FilePermission} for the local path. * @@ -352,13 +354,14 @@ /** * Retrieves a socket associated with this channel if it is an IP - * channel. The operation is not supported for unix domain channels. + * channel. The operation is not supported for Unix Domain channels. * *

The returned object will not declare any public methods that are not * declared in the {@link java.net.Socket} class.

* * @return A socket associated with this channel - * @throws UnsupportedOperationException is this is a Unix domain channel + * + * @throws UnsupportedOperationException is this is a Unix Domain channel */ public abstract Socket socket(); @@ -400,7 +403,7 @@ * java.lang.SecurityManager#checkConnect checkConnect} method permits * connecting to the address and port number of the given remote endpoint. * - *

For unix domain channels, this method performs a security + *

For Unix Domain channels, this method performs a security * manager {@link SecurityManager#checkPermission(Permission)} using * a {@link java.io.FilePermission} constructed with the path from the * destination address and "read,write" as the actions. @@ -512,7 +515,7 @@ * socket address then the return value from this method is of type {@link * java.net.InetSocketAddress}. * - *

Where the channel is bound and connected to a Unix domain + *

Where the channel is bound and connected to a Unix Domain * address, the returned address is a {@link UnixDomainSocketAddress} * * @return The remote address; {@code null} if the channel's socket is not @@ -582,13 +585,16 @@ * {@link java.net.InetAddress#getLoopbackAddress loopback} address and the * local port of the channel's socket is returned. *

- * If there is a security manager set and this is an unix domain channel, - * then this returns a {@link UnixDomainSocketAddress} corresponding to the - * bound address. + * If there is a security manager set and this is a Unix Domain channel, + * {@code checkPermission} is called with a {@link FilePermission} whose {@code + * path} is the path of the bound address and actions is {@code "read"} + * and if the operation is allowed a {@link UnixDomainSocketAddress} + * corresponding to the bound address is returned. If not, then an address with + * an empty path is returned. * * @return The {@code SocketAddress} that the socket is bound to, or the - * {@code SocketAddress} representing the loopback address if - * denied by the security manager, or {@code null} if the + * {@code SocketAddress} representing the loopback address or an + * empty pathname, if denied by the security manager, or {@code null} if the * channel's socket is not bound * * @throws ClosedChannelException {@inheritDoc} diff -r aca099f4b3ec -r 5c79956cc7d7 src/java.base/unix/classes/sun/nio/ch/InheritedChannel.java --- a/src/java.base/unix/classes/sun/nio/ch/InheritedChannel.java Tue Nov 05 18:34:02 2019 +0000 +++ b/src/java.base/unix/classes/sun/nio/ch/InheritedChannel.java Fri Nov 08 09:46:55 2019 +0000 @@ -115,6 +115,21 @@ } } + public static class InheritedUnixServerSocketChannelImpl extends UnixDomainServerSocketChannelImpl { + + InheritedUnixServerSocketChannelImpl(SelectorProvider sp, FileDescriptor fd) + throws IOException + { + super(sp, fd, true); + } + + @Override + protected void implCloseSelectableChannel() throws IOException { + super.implCloseSelectableChannel(); + detachIOStreams(); + } + } + public static class InheritedInetServerSocketChannelImpl extends InetServerSocketChannelImpl { @@ -214,8 +229,7 @@ if (isConnected(fdVal)) { return new InheritedUnixSocketChannelImpl(provider, fd); } else { - // listener. unsupported. - return null; + return new InheritedUnixServerSocketChannelImpl(provider, fd); } } InetAddress ia = peerAddress0(fdVal); diff -r aca099f4b3ec -r 5c79956cc7d7 src/java.base/windows/native/libnio/ch/Net.c --- a/src/java.base/windows/native/libnio/ch/Net.c Tue Nov 05 18:34:02 2019 +0000 +++ b/src/java.base/windows/native/libnio/ch/Net.c Fri Nov 08 09:46:55 2019 +0000 @@ -141,7 +141,7 @@ Java_sun_nio_ch_Net_unixDomainSocket0(JNIEnv *env, jclass cl) { SOCKET fd = socket(PF_UNIX, SOCK_STREAM, 0); - if (fd < 0) { + if (fd == INVALID_SOCKET) { return handleSocketError(env, errno); } return (int)fd; diff -r aca099f4b3ec -r 5c79956cc7d7 test/jdk/jdk/nio/Basic.java --- a/test/jdk/jdk/nio/Basic.java Tue Nov 05 18:34:02 2019 +0000 +++ b/test/jdk/jdk/nio/Basic.java Fri Nov 08 09:46:55 2019 +0000 @@ -265,11 +265,20 @@ } private static FileDescriptor getFD(SocketChannel sc) { + return getFD1(sc, sc.getClass()); + } + + private static FileDescriptor getFD1(SocketChannel sc, Class clazz) { try { - Class clazz = sc.getClass(); Field f = clazz.getDeclaredField("fd"); f.setAccessible(true); return (FileDescriptor) f.get(sc); + } catch (NoSuchFieldException e1) { + Class superclass = clazz.getSuperclass(); + if (superclass == null) + throw new Error(e1); + else + return getFD1(sc, superclass); } catch (Exception e) { throw new Error(e); }