# HG changeset patch # User michaelm # Date 1573726588 0 # Node ID 998df1368ccae3f1a78979df0d2f8bf13a831993 # Parent 7917f95f74c47240b3ffc65c1eebced5fbc97bf6 unixdomainchannels: unix domain automatic bind diff -r 7917f95f74c4 -r 998df1368cca src/java.base/share/classes/java/nio/channels/ServerSocketChannel.java --- a/src/java.base/share/classes/java/nio/channels/ServerSocketChannel.java Thu Nov 14 09:06:10 2019 +0000 +++ b/src/java.base/share/classes/java/nio/channels/ServerSocketChannel.java Thu Nov 14 10:16:28 2019 +0000 @@ -218,16 +218,19 @@ *
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. + * another channel can bind to the same name. Also, Unix Domain ServerSocketChannels + * must be bound to an explicit address. * * @param local - * The address to bind the socket, or {@code null} to bind to an - * automatically assigned socket address + * The address to bind the socket, or {@code null} to bind an IP channel to + * an automatically assigned socket address * @param backlog * The maximum number of pending connections * * @return This channel * + * @throws BindException + * If this is a Unix domain channel and {@code local} is {@code null} * @throws AlreadyBoundException * If the socket is already bound * @throws UnsupportedAddressTypeException diff -r 7917f95f74c4 -r 998df1368cca src/java.base/share/classes/sun/nio/ch/Net.java --- a/src/java.base/share/classes/sun/nio/ch/Net.java Thu Nov 14 09:06:10 2019 +0000 +++ b/src/java.base/share/classes/sun/nio/ch/Net.java Thu Nov 14 10:16:28 2019 +0000 @@ -711,7 +711,7 @@ public static UnixDomainSocketAddress checkUnixAddress(SocketAddress sa) { if (sa == null) - throw new NullPointerException(); + return null; if (!(sa instanceof UnixDomainSocketAddress)) throw new UnsupportedAddressTypeException(); UnixDomainSocketAddress usa = (UnixDomainSocketAddress)sa; diff -r 7917f95f74c4 -r 998df1368cca src/java.base/share/classes/sun/nio/ch/UnixDomainServerSocketChannelImpl.java --- a/src/java.base/share/classes/sun/nio/ch/UnixDomainServerSocketChannelImpl.java Thu Nov 14 09:06:10 2019 +0000 +++ b/src/java.base/share/classes/sun/nio/ch/UnixDomainServerSocketChannelImpl.java Thu Nov 14 10:16:28 2019 +0000 @@ -27,6 +27,7 @@ import java.io.FileDescriptor; import java.io.IOException; +import java.net.BindException; import java.net.ServerSocket; import java.net.SocketAddress; import java.net.SocketOption; @@ -135,6 +136,9 @@ @Override public ServerSocketChannel bind(SocketAddress local, int backlog) throws IOException { + if (local == null) + throw new BindException("automatic bind not possible for Unix domain servers"); + synchronized (stateLock) { ensureOpen(); if (localAddress != null) diff -r 7917f95f74c4 -r 998df1368cca src/java.base/share/classes/sun/nio/ch/UnixDomainSocketChannelImpl.java --- a/src/java.base/share/classes/sun/nio/ch/UnixDomainSocketChannelImpl.java Thu Nov 14 09:06:10 2019 +0000 +++ b/src/java.base/share/classes/sun/nio/ch/UnixDomainSocketChannelImpl.java Thu Nov 14 10:16:28 2019 +0000 @@ -172,8 +172,6 @@ throw new ConnectionPendingException(); if (localAddress != null) throw new AlreadyBoundException(); - if (local == null) - throw new NullPointerException(); // TODO: ?? UnixDomainSocketAddress usa = Net.checkUnixAddress(local); Net.unixDomainBind(fd, usa); localAddress = Net.localUnixAddress(fd); diff -r 7917f95f74c4 -r 998df1368cca src/java.base/unix/native/libnio/ch/Net.c --- a/src/java.base/unix/native/libnio/ch/Net.c Thu Nov 14 09:06:10 2019 +0000 +++ b/src/java.base/unix/native/libnio/ch/Net.c Thu Nov 14 10:16:28 2019 +0000 @@ -110,6 +110,9 @@ int sa_len = 0; int rv = 0; + if (uaddr == NULL) + return; /* Rely on implicit bind */ + if (NET_UnixSocketAddressToSockaddr(env, uaddr, &sa, &sa_len) != 0) return;