< prev index next >
src/java.base/windows/classes/sun/nio/ch/PipeImpl.java
Print this page
*** 29,40 ****
--- 29,45 ----
package sun.nio.ch;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
+ import java.net.SocketAddress;
+ import java.net.UnixDomainSocketAddress;
+ import java.net.StandardProtocolFamily;
import java.nio.*;
import java.nio.channels.*;
+ import java.nio.file.Files;
+ import java.nio.file.Paths;
import java.nio.channels.spi.*;
import java.security.AccessController;
import java.security.PrivilegedExceptionAction;
import java.security.PrivilegedActionException;
import java.security.SecureRandom;
*** 101,127 ****
@Override
public void run() {
ServerSocketChannel ssc = null;
SocketChannel sc1 = null;
SocketChannel sc2 = null;
try {
// Create secret with a backing array.
ByteBuffer secret = ByteBuffer.allocate(NUM_SECRET_BYTES);
ByteBuffer bb = ByteBuffer.allocate(NUM_SECRET_BYTES);
- // Loopback address
- InetAddress lb = InetAddress.getLoopbackAddress();
- assert(lb.isLoopbackAddress());
- InetSocketAddress sa = null;
for(;;) {
// Bind ServerSocketChannel to a port on the loopback
// address
if (ssc == null || !ssc.isOpen()) {
! ssc = ServerSocketChannel.open();
! ssc.socket().bind(new InetSocketAddress(lb, 0));
! sa = new InetSocketAddress(lb, ssc.socket().getLocalPort());
}
// Establish connection (assume connections are eagerly
// accepted)
sc1 = SocketChannel.open(sa);
--- 106,129 ----
@Override
public void run() {
ServerSocketChannel ssc = null;
SocketChannel sc1 = null;
SocketChannel sc2 = null;
+ // Loopback address
+ SocketAddress sa = null;
try {
// Create secret with a backing array.
ByteBuffer secret = ByteBuffer.allocate(NUM_SECRET_BYTES);
ByteBuffer bb = ByteBuffer.allocate(NUM_SECRET_BYTES);
for(;;) {
// Bind ServerSocketChannel to a port on the loopback
// address
if (ssc == null || !ssc.isOpen()) {
! ssc = getServer();
! sa = ssc.getLocalAddress();
}
// Establish connection (assume connections are eagerly
// accepted)
sc1 = SocketChannel.open(sa);
*** 158,167 ****
--- 160,171 ----
ioe = e;
} finally {
try {
if (ssc != null)
ssc.close();
+ if (sa instanceof UnixDomainSocketAddress)
+ Files.delete(((UnixDomainSocketAddress)sa).getPath());
} catch (IOException e2) {}
}
}
}
}
*** 180,185 ****
--- 184,202 ----
public SinkChannel sink() {
return sink;
}
+ private static ServerSocketChannel getServer() throws IOException {
+ ServerSocketChannel server;
+ try {
+ server = ServerSocketChannel.open(StandardProtocolFamily.UNIX);
+ server.bind(null);
+ } catch (UnsupportedOperationException e) {
+ server = ServerSocketChannel.open();
+ InetAddress lb = InetAddress.getLoopbackAddress();
+ server.bind(new InetSocketAddress(lb, 0));
+ }
+ return server;
+ }
+
}
< prev index next >