mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8280944: Enable Unix domain sockets in Windows Selector notification mechanism
Reviewed-by: dfuchs, alanb
This commit is contained in:
parent
ce71e8b281
commit
87ab0994de
3 changed files with 34 additions and 13 deletions
|
@ -33,6 +33,7 @@ import java.net.InetAddress;
|
|||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.StandardSocketOptions;
|
||||
import java.net.UnixDomainSocketAddress;
|
||||
import java.nio.*;
|
||||
import java.nio.channels.*;
|
||||
import java.nio.file.Files;
|
||||
|
@ -44,6 +45,7 @@ import java.security.PrivilegedActionException;
|
|||
import java.security.SecureRandom;
|
||||
import java.util.Random;
|
||||
|
||||
import static java.net.StandardProtocolFamily.UNIX;
|
||||
|
||||
/**
|
||||
* A simple Pipe implementation based on a socket connection.
|
||||
|
@ -67,12 +69,14 @@ class PipeImpl
|
|||
{
|
||||
|
||||
private final SelectorProvider sp;
|
||||
private final boolean preferUnixDomain;
|
||||
private IOException ioe;
|
||||
SourceChannelImpl source;
|
||||
SinkChannelImpl sink;
|
||||
|
||||
private Initializer(SelectorProvider sp) {
|
||||
private Initializer(SelectorProvider sp, boolean preferUnixDomain) {
|
||||
this.sp = sp;
|
||||
this.preferUnixDomain = preferUnixDomain;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -120,7 +124,7 @@ class PipeImpl
|
|||
// Bind ServerSocketChannel to a port on the loopback
|
||||
// address
|
||||
if (ssc == null || !ssc.isOpen()) {
|
||||
ssc = createListener();
|
||||
ssc = createListener(preferUnixDomain);
|
||||
sa = ssc.getLocalAddress();
|
||||
}
|
||||
|
||||
|
@ -162,6 +166,9 @@ class PipeImpl
|
|||
try {
|
||||
if (ssc != null)
|
||||
ssc.close();
|
||||
if (sa instanceof UnixDomainSocketAddress uaddr) {
|
||||
Files.deleteIfExists(uaddr.getPath());
|
||||
}
|
||||
} catch (IOException e2) {}
|
||||
}
|
||||
}
|
||||
|
@ -169,21 +176,24 @@ class PipeImpl
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates a Pipe implementation that supports buffering.
|
||||
* Creates a (TCP) Pipe implementation that supports buffering.
|
||||
*/
|
||||
PipeImpl(SelectorProvider sp) throws IOException {
|
||||
this(sp, true);
|
||||
this(sp, true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates Pipe implementation that supports optionally buffering.
|
||||
* Creates Pipe implementation that supports optionally buffering
|
||||
* and is TCP by default, but if Unix domain is supported and
|
||||
* preferAfUnix is true, then Unix domain sockets are used.
|
||||
*
|
||||
* @implNote Uses a loopback connection. When buffering is
|
||||
* disabled then it sets TCP_NODELAY on the sink channel.
|
||||
* @param preferAfUnix use Unix domain sockets if supported
|
||||
*
|
||||
* @param buffering if false set TCP_NODELAY on TCP sockets
|
||||
*/
|
||||
@SuppressWarnings("removal")
|
||||
PipeImpl(SelectorProvider sp, boolean buffering) throws IOException {
|
||||
Initializer initializer = new Initializer(sp);
|
||||
PipeImpl(SelectorProvider sp, boolean preferAfUnix, boolean buffering) throws IOException {
|
||||
Initializer initializer = new Initializer(sp, preferAfUnix);
|
||||
try {
|
||||
AccessController.doPrivileged(initializer);
|
||||
SinkChannelImpl sink = initializer.sink;
|
||||
|
@ -205,8 +215,19 @@ class PipeImpl
|
|||
return sink;
|
||||
}
|
||||
|
||||
private static ServerSocketChannel createListener() throws IOException {
|
||||
ServerSocketChannel listener = ServerSocketChannel.open();
|
||||
private static ServerSocketChannel createListener(boolean preferUnixDomain) throws IOException {
|
||||
ServerSocketChannel listener = null;
|
||||
if (preferUnixDomain && UnixDomainSockets.isSupported()) {
|
||||
try {
|
||||
listener = ServerSocketChannel.open(UNIX);
|
||||
listener.bind(null);
|
||||
return listener;
|
||||
} catch (IOException | UnsupportedOperationException e) {
|
||||
if (listener != null)
|
||||
listener.close();
|
||||
}
|
||||
}
|
||||
listener = ServerSocketChannel.open();
|
||||
InetAddress lb = InetAddress.getLoopbackAddress();
|
||||
listener.bind(new InetSocketAddress(lb, 0));
|
||||
return listener;
|
||||
|
|
|
@ -75,7 +75,7 @@ class WEPollSelectorImpl extends SelectorImpl {
|
|||
|
||||
// wakeup support
|
||||
try {
|
||||
this.pipe = new PipeImpl(sp, /*buffering*/ false);
|
||||
this.pipe = new PipeImpl(sp, /* AF_UNIX */ true, /*buffering*/ false);
|
||||
} catch (IOException ioe) {
|
||||
WEPoll.freePollArray(pollArrayAddress);
|
||||
WEPoll.close(eph);
|
||||
|
|
|
@ -139,7 +139,7 @@ class WindowsSelectorImpl extends SelectorImpl {
|
|||
WindowsSelectorImpl(SelectorProvider sp) throws IOException {
|
||||
super(sp);
|
||||
pollWrapper = new PollArrayWrapper(INIT_CAP);
|
||||
wakeupPipe = new PipeImpl(sp, false);
|
||||
wakeupPipe = new PipeImpl(sp, /* AF_UNIX */ true, /*buffering*/ false);
|
||||
wakeupSourceFd = ((SelChImpl)wakeupPipe.source()).getFDVal();
|
||||
wakeupSinkFd = ((SelChImpl)wakeupPipe.sink()).getFDVal();
|
||||
pollWrapper.addWakeupSocket(wakeupSourceFd, 0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue