提交 1dc40198 编写于 作者: A asaha

Merge

...@@ -86,7 +86,7 @@ final class UNIXProcess extends Process { ...@@ -86,7 +86,7 @@ final class UNIXProcess extends Process {
java.security.AccessController.doPrivileged( java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Void>() { public Void run() { new java.security.PrivilegedAction<Void>() { public Void run() {
if (std_fds[0] == -1) if (std_fds[0] == -1)
stdin_stream = new ProcessBuilder.NullOutputStream(); stdin_stream = ProcessBuilder.NullOutputStream.INSTANCE;
else { else {
FileDescriptor stdin_fd = new FileDescriptor(); FileDescriptor stdin_fd = new FileDescriptor();
fdAccess.set(stdin_fd, std_fds[0]); fdAccess.set(stdin_fd, std_fds[0]);
...@@ -95,7 +95,7 @@ final class UNIXProcess extends Process { ...@@ -95,7 +95,7 @@ final class UNIXProcess extends Process {
} }
if (std_fds[1] == -1) if (std_fds[1] == -1)
stdout_stream = new ProcessBuilder.NullInputStream(); stdout_stream = ProcessBuilder.NullInputStream.INSTANCE;
else { else {
FileDescriptor stdout_fd = new FileDescriptor(); FileDescriptor stdout_fd = new FileDescriptor();
fdAccess.set(stdout_fd, std_fds[1]); fdAccess.set(stdout_fd, std_fds[1]);
...@@ -104,7 +104,7 @@ final class UNIXProcess extends Process { ...@@ -104,7 +104,7 @@ final class UNIXProcess extends Process {
} }
if (std_fds[2] == -1) if (std_fds[2] == -1)
stderr_stream = new ProcessBuilder.NullInputStream(); stderr_stream = ProcessBuilder.NullInputStream.INSTANCE;
else { else {
FileDescriptor stderr_fd = new FileDescriptor(); FileDescriptor stderr_fd = new FileDescriptor();
fdAccess.set(stderr_fd, std_fds[2]); fdAccess.set(stderr_fd, std_fds[2]);
......
...@@ -159,7 +159,7 @@ final class ProcessImpl extends Process { ...@@ -159,7 +159,7 @@ final class ProcessImpl extends Process {
new java.security.PrivilegedAction<Void>() { new java.security.PrivilegedAction<Void>() {
public Void run() { public Void run() {
if (stdHandles[0] == -1L) if (stdHandles[0] == -1L)
stdin_stream = new ProcessBuilder.NullOutputStream(); stdin_stream = ProcessBuilder.NullOutputStream.INSTANCE;
else { else {
FileDescriptor stdin_fd = new FileDescriptor(); FileDescriptor stdin_fd = new FileDescriptor();
fdAccess.setHandle(stdin_fd, stdHandles[0]); fdAccess.setHandle(stdin_fd, stdHandles[0]);
...@@ -168,7 +168,7 @@ final class ProcessImpl extends Process { ...@@ -168,7 +168,7 @@ final class ProcessImpl extends Process {
} }
if (stdHandles[1] == -1L) if (stdHandles[1] == -1L)
stdout_stream = new ProcessBuilder.NullInputStream(); stdout_stream = ProcessBuilder.NullInputStream.INSTANCE;
else { else {
FileDescriptor stdout_fd = new FileDescriptor(); FileDescriptor stdout_fd = new FileDescriptor();
fdAccess.setHandle(stdout_fd, stdHandles[1]); fdAccess.setHandle(stdout_fd, stdHandles[1]);
...@@ -177,7 +177,7 @@ final class ProcessImpl extends Process { ...@@ -177,7 +177,7 @@ final class ProcessImpl extends Process {
} }
if (stdHandles[2] == -1L) if (stdHandles[2] == -1L)
stderr_stream = new ProcessBuilder.NullInputStream(); stderr_stream = ProcessBuilder.NullInputStream.INSTANCE;
else { else {
FileDescriptor stderr_fd = new FileDescriptor(); FileDescriptor stderr_fd = new FileDescriptor();
fdAccess.setHandle(stderr_fd, stdHandles[2]); fdAccess.setHandle(stderr_fd, stdHandles[2]);
......
...@@ -752,18 +752,9 @@ com/sun/nio/sctp/SctpChannel/Shutdown.java generic-all ...@@ -752,18 +752,9 @@ com/sun/nio/sctp/SctpChannel/Shutdown.java generic-all
# at SetLastModified.main(SetLastModified.java:107) # at SetLastModified.main(SetLastModified.java:107)
java/io/File/SetLastModified.java generic-all java/io/File/SetLastModified.java generic-all
# Fails on Solaris 10 x64, address already in use
java/nio/channels/DatagramChannel/SRTest.java generic-all
# Fails on Solaris 10 x86, times out
java/nio/channels/DatagramChannel/Sender.java generic-all
# Fails on Fedora 9 x86, address in use # Fails on Fedora 9 x86, address in use
java/nio/channels/Selector/SelectWrite.java generic-all java/nio/channels/Selector/SelectWrite.java generic-all
# Fails on Fedora 9 32bit times out
java/nio/channels/DatagramChannel/EmptyBuffer.java generic-all
# Fails on Windows 2000, times out # Fails on Windows 2000, times out
java/nio/channels/FileChannel/Transfer.java generic-all java/nio/channels/FileChannel/Transfer.java generic-all
...@@ -821,12 +812,6 @@ java/nio/channels/AsynchronousSocketChannel/Leaky.java windows-5.0 ...@@ -821,12 +812,6 @@ java/nio/channels/AsynchronousSocketChannel/Leaky.java windows-5.0
java/nio/channels/AsynchronousSocketChannel/StressLoopback.java windows-5.0 java/nio/channels/AsynchronousSocketChannel/StressLoopback.java windows-5.0
java/nio/channels/Channels/Basic2.java windows-5.0 java/nio/channels/Channels/Basic2.java windows-5.0
# Solaris sparc timeout
java/nio/channels/DatagramChannel/Connect.java generic-all
# Solaris i586 timeouts
java/nio/channels/DatagramChannel/EmptyBuffer.java solaris-all
# Failed loopback connection? On windows 32bit? # Failed loopback connection? On windows 32bit?
# Considered a stress test, can consume all resources. # Considered a stress test, can consume all resources.
java/nio/channels/Selector/LotsOfChannels.java generic-all java/nio/channels/Selector/LotsOfChannels.java generic-all
......
...@@ -42,15 +42,15 @@ public class Connect { ...@@ -42,15 +42,15 @@ public class Connect {
} }
static void test() throws Exception { static void test() throws Exception {
invoke(new Actor(), new Reactor()); Reactor r = new Reactor();
Actor a = new Actor(r.port());
invoke(a, r);
} }
static void invoke(Sprintable reader, Sprintable writer) throws Exception { static void invoke(Sprintable reader, Sprintable writer) throws Exception {
Thread writerThread = new Thread(writer); Thread writerThread = new Thread(writer);
writerThread.start(); writerThread.start();
while (!writer.ready())
Thread.sleep(50);
Thread readerThread = new Thread(reader); Thread readerThread = new Thread(reader);
readerThread.start(); readerThread.start();
...@@ -64,34 +64,31 @@ public class Connect { ...@@ -64,34 +64,31 @@ public class Connect {
public interface Sprintable extends Runnable { public interface Sprintable extends Runnable {
public void throwException() throws Exception; public void throwException() throws Exception;
public boolean ready();
} }
public static class Actor implements Sprintable { public static class Actor implements Sprintable {
final int port;
Exception e = null; Exception e = null;
Actor(int port) {
this.port = port;
}
public void throwException() throws Exception { public void throwException() throws Exception {
if (e != null) if (e != null)
throw e; throw e;
} }
private volatile boolean ready = false;
public boolean ready() {
return ready;
}
public void run() { public void run() {
try { try {
DatagramChannel dc = DatagramChannel.open(); DatagramChannel dc = DatagramChannel.open();
ready = true;
// Send a message // Send a message
ByteBuffer bb = ByteBuffer.allocateDirect(256); ByteBuffer bb = ByteBuffer.allocateDirect(256);
bb.put("hello".getBytes()); bb.put("hello".getBytes());
bb.flip(); bb.flip();
InetAddress address = InetAddress.getLocalHost(); InetAddress address = InetAddress.getLocalHost();
InetSocketAddress isa = new InetSocketAddress(address, 8888); InetSocketAddress isa = new InetSocketAddress(address, port);
dc.connect(isa); dc.connect(isa);
dc.write(bb); dc.write(bb);
...@@ -123,26 +120,26 @@ public class Connect { ...@@ -123,26 +120,26 @@ public class Connect {
} }
public static class Reactor implements Sprintable { public static class Reactor implements Sprintable {
final DatagramChannel dc;
Exception e = null; Exception e = null;
public void throwException() throws Exception { Reactor() throws IOException {
if (e != null) dc = DatagramChannel.open().bind(new InetSocketAddress(0));
throw e;
} }
private volatile boolean ready = false; int port() {
return dc.socket().getLocalPort();
}
public boolean ready() { public void throwException() throws Exception {
return ready; if (e != null)
throw e;
} }
public void run() { public void run() {
try { try {
// Listen for a message // Listen for a message
DatagramChannel dc = DatagramChannel.open();
dc.socket().bind(new InetSocketAddress(8888));
ByteBuffer bb = ByteBuffer.allocateDirect(100); ByteBuffer bb = ByteBuffer.allocateDirect(100);
ready = true;
SocketAddress sa = dc.receive(bb); SocketAddress sa = dc.receive(bb);
bb.flip(); bb.flip();
CharBuffer cb = Charset.forName("US-ASCII"). CharBuffer cb = Charset.forName("US-ASCII").
......
...@@ -42,18 +42,16 @@ public class EmptyBuffer { ...@@ -42,18 +42,16 @@ public class EmptyBuffer {
} }
static void test() throws Exception { static void test() throws Exception {
Sprintable server = new Server(); Server server = new Server();
Thread serverThread = new Thread(server); Thread serverThread = new Thread(server);
serverThread.start(); serverThread.start();
while (!server.ready())
Thread.sleep(50);
DatagramChannel dc = DatagramChannel.open(); DatagramChannel dc = DatagramChannel.open();
ByteBuffer bb = ByteBuffer.allocateDirect(12); ByteBuffer bb = ByteBuffer.allocateDirect(12);
bb.order(ByteOrder.BIG_ENDIAN); bb.order(ByteOrder.BIG_ENDIAN);
bb.putInt(1).putLong(1); bb.putInt(1).putLong(1);
bb.flip(); bb.flip();
InetAddress address = InetAddress.getLocalHost(); InetAddress address = InetAddress.getLocalHost();
InetSocketAddress isa = new InetSocketAddress(address, 8888); InetSocketAddress isa = new InetSocketAddress(address, server.port());
dc.connect(isa); dc.connect(isa);
dc.write(bb); dc.write(bb);
bb.rewind(); bb.rewind();
...@@ -65,22 +63,21 @@ public class EmptyBuffer { ...@@ -65,22 +63,21 @@ public class EmptyBuffer {
server.throwException(); server.throwException();
} }
public interface Sprintable extends Runnable { public static class Server implements Runnable {
public void throwException() throws Exception; final DatagramChannel dc;
public boolean ready();
}
public static class Server implements Sprintable {
Exception e = null; Exception e = null;
private volatile boolean ready = false;
public void throwException() throws Exception { Server() throws IOException {
if (e != null) this.dc = DatagramChannel.open().bind(new InetSocketAddress(0));
throw e;
} }
public boolean ready() { int port() {
return ready; return dc.socket().getLocalPort();
}
void throwException() throws Exception {
if (e != null)
throw e;
} }
void showBuffer(String s, ByteBuffer bb) { void showBuffer(String s, ByteBuffer bb) {
...@@ -97,9 +94,6 @@ public class EmptyBuffer { ...@@ -97,9 +94,6 @@ public class EmptyBuffer {
SocketAddress sa = null; SocketAddress sa = null;
int numberReceived = 0; int numberReceived = 0;
try { try {
DatagramChannel dc = DatagramChannel.open();
dc.socket().bind(new InetSocketAddress(8888));
ready = true;
ByteBuffer bb = ByteBuffer.allocateDirect(12); ByteBuffer bb = ByteBuffer.allocateDirect(12);
bb.clear(); bb.clear();
// Only one clear. The buffer will be full after // Only one clear. The buffer will be full after
......
...@@ -33,7 +33,7 @@ import java.nio.channels.*; ...@@ -33,7 +33,7 @@ import java.nio.channels.*;
public class NoSender { public class NoSender {
public static void main(String argv[]) throws Exception { public static void main(String argv[]) throws Exception {
DatagramChannel dc = DatagramChannel.open(); DatagramChannel dc = DatagramChannel.open();
dc.socket().bind(new InetSocketAddress(5441)); dc.socket().bind(new InetSocketAddress(0));
dc.configureBlocking(false); dc.configureBlocking(false);
ByteBuffer buf1 = ByteBuffer.allocateDirect(256); ByteBuffer buf1 = ByteBuffer.allocateDirect(256);
SocketAddress sa1 = dc.receive(buf1); SocketAddress sa1 = dc.receive(buf1);
......
...@@ -42,16 +42,23 @@ public class SRTest { ...@@ -42,16 +42,23 @@ public class SRTest {
} }
static void test() throws Exception { static void test() throws Exception {
invoke(new ClassicReader(), new ClassicWriter()); ClassicReader classicReader;
NioReader nioReader;
classicReader = new ClassicReader();
invoke(classicReader, new ClassicWriter(classicReader.port()));
log.println("Classic RW: OK"); log.println("Classic RW: OK");
invoke(new ClassicReader(), new NioWriter()); classicReader = new ClassicReader();
invoke(classicReader, new NioWriter(classicReader.port()));
log.println("Classic R, Nio W: OK"); log.println("Classic R, Nio W: OK");
invoke(new NioReader(), new ClassicWriter()); nioReader = new NioReader();
invoke(nioReader, new ClassicWriter(nioReader.port()));
log.println("Classic W, Nio R: OK"); log.println("Classic W, Nio R: OK");
invoke(new NioReader(), new NioWriter()); nioReader = new NioReader();
invoke(nioReader, new NioWriter(nioReader.port()));
log.println("Nio RW: OK"); log.println("Nio RW: OK");
} }
...@@ -75,8 +82,13 @@ public class SRTest { ...@@ -75,8 +82,13 @@ public class SRTest {
} }
public static class ClassicWriter implements Sprintable { public static class ClassicWriter implements Sprintable {
final int port;
Exception e = null; Exception e = null;
ClassicWriter(int port) {
this.port = port;
}
public void throwException() throws Exception { public void throwException() throws Exception {
if (e != null) if (e != null)
throw e; throw e;
...@@ -89,7 +101,7 @@ public class SRTest { ...@@ -89,7 +101,7 @@ public class SRTest {
byte[] data = dataString.getBytes(); byte[] data = dataString.getBytes();
InetAddress address = InetAddress.getLocalHost(); InetAddress address = InetAddress.getLocalHost();
DatagramPacket dp = new DatagramPacket(data, data.length, DatagramPacket dp = new DatagramPacket(data, data.length,
address, 8888); address, port);
ds.send(dp); ds.send(dp);
Thread.sleep(50); Thread.sleep(50);
ds.send(dp); ds.send(dp);
...@@ -100,8 +112,13 @@ public class SRTest { ...@@ -100,8 +112,13 @@ public class SRTest {
} }
public static class NioWriter implements Sprintable { public static class NioWriter implements Sprintable {
final int port;
Exception e = null; Exception e = null;
NioWriter(int port) {
this.port = port;
}
public void throwException() throws Exception { public void throwException() throws Exception {
if (e != null) if (e != null)
throw e; throw e;
...@@ -114,7 +131,7 @@ public class SRTest { ...@@ -114,7 +131,7 @@ public class SRTest {
bb.put("hello".getBytes()); bb.put("hello".getBytes());
bb.flip(); bb.flip();
InetAddress address = InetAddress.getLocalHost(); InetAddress address = InetAddress.getLocalHost();
InetSocketAddress isa = new InetSocketAddress(address, 8888); InetSocketAddress isa = new InetSocketAddress(address, port);
dc.send(bb, isa); dc.send(bb, isa);
Thread.sleep(50); Thread.sleep(50);
dc.send(bb, isa); dc.send(bb, isa);
...@@ -125,8 +142,17 @@ public class SRTest { ...@@ -125,8 +142,17 @@ public class SRTest {
} }
public static class ClassicReader implements Sprintable { public static class ClassicReader implements Sprintable {
final DatagramSocket ds;
Exception e = null; Exception e = null;
ClassicReader() throws IOException {
this.ds = new DatagramSocket();
}
int port() {
return ds.getLocalPort();
}
public void throwException() throws Exception { public void throwException() throws Exception {
if (e != null) if (e != null)
throw e; throw e;
...@@ -136,7 +162,6 @@ public class SRTest { ...@@ -136,7 +162,6 @@ public class SRTest {
try { try {
byte[] buf = new byte[256]; byte[] buf = new byte[256];
DatagramPacket dp = new DatagramPacket(buf, buf.length); DatagramPacket dp = new DatagramPacket(buf, buf.length);
DatagramSocket ds = new DatagramSocket(8888);
ds.receive(dp); ds.receive(dp);
String received = new String(dp.getData()); String received = new String(dp.getData());
log.println(received); log.println(received);
...@@ -148,8 +173,17 @@ public class SRTest { ...@@ -148,8 +173,17 @@ public class SRTest {
} }
public static class NioReader implements Sprintable { public static class NioReader implements Sprintable {
final DatagramChannel dc;
Exception e = null; Exception e = null;
NioReader() throws IOException {
this.dc = DatagramChannel.open().bind(new InetSocketAddress(0));
}
int port() {
return dc.socket().getLocalPort();
}
public void throwException() throws Exception { public void throwException() throws Exception {
if (e != null) if (e != null)
throw e; throw e;
...@@ -157,8 +191,6 @@ public class SRTest { ...@@ -157,8 +191,6 @@ public class SRTest {
public void run() { public void run() {
try { try {
DatagramChannel dc = DatagramChannel.open();
dc.socket().bind(new InetSocketAddress(8888));
ByteBuffer bb = ByteBuffer.allocateDirect(100); ByteBuffer bb = ByteBuffer.allocateDirect(100);
SocketAddress sa = dc.receive(bb); SocketAddress sa = dc.receive(bb);
bb.flip(); bb.flip();
......
...@@ -42,13 +42,11 @@ public class Sender { ...@@ -42,13 +42,11 @@ public class Sender {
} }
static void test() throws Exception { static void test() throws Exception {
Sprintable server = new Server(); Server server = new Server();
Sprintable client = new Client(); Client client = new Client(server.port());
Thread serverThread = new Thread(server); Thread serverThread = new Thread(server);
serverThread.start(); serverThread.start();
while (!server.ready())
Thread.sleep(50);
Thread clientThread = new Thread(client); Thread clientThread = new Thread(client);
clientThread.start(); clientThread.start();
...@@ -60,23 +58,17 @@ public class Sender { ...@@ -60,23 +58,17 @@ public class Sender {
client.throwException(); client.throwException();
} }
public interface Sprintable extends Runnable { public static class Client implements Runnable {
public void throwException() throws Exception; final int port;
public boolean ready();
}
public static class Client implements Sprintable {
Exception e = null; Exception e = null;
public void throwException() throws Exception { Client(int port) {
if (e != null) this.port = port;
throw e;
} }
private volatile boolean ready = false; void throwException() throws Exception {
if (e != null)
public boolean ready() { throw e;
return ready;
} }
public void run() { public void run() {
...@@ -87,7 +79,7 @@ public class Sender { ...@@ -87,7 +79,7 @@ public class Sender {
bb.putInt(1).putLong(1); bb.putInt(1).putLong(1);
bb.flip(); bb.flip();
InetAddress address = InetAddress.getLocalHost(); InetAddress address = InetAddress.getLocalHost();
InetSocketAddress isa = new InetSocketAddress(address, 8888); InetSocketAddress isa = new InetSocketAddress(address, port);
dc.connect(isa); dc.connect(isa);
dc.write(bb); dc.write(bb);
} catch (Exception ex) { } catch (Exception ex) {
...@@ -96,17 +88,21 @@ public class Sender { ...@@ -96,17 +88,21 @@ public class Sender {
} }
} }
public static class Server implements Sprintable { public static class Server implements Runnable {
final DatagramChannel dc;
Exception e = null; Exception e = null;
private volatile boolean ready = false;
public void throwException() throws Exception { Server() throws IOException {
if (e != null) dc = DatagramChannel.open().bind(new InetSocketAddress(0));
throw e; }
int port() {
return dc.socket().getLocalPort();
} }
public boolean ready() { void throwException() throws Exception {
return ready; if (e != null)
throw e;
} }
void showBuffer(String s, ByteBuffer bb) { void showBuffer(String s, ByteBuffer bb) {
...@@ -123,13 +119,10 @@ public class Sender { ...@@ -123,13 +119,10 @@ public class Sender {
SocketAddress sa = null; SocketAddress sa = null;
try { try {
DatagramChannel dc = DatagramChannel.open();
dc.socket().bind(new InetSocketAddress(8888));
dc.configureBlocking(false);
ready = true;
ByteBuffer bb = ByteBuffer.allocateDirect(12); ByteBuffer bb = ByteBuffer.allocateDirect(12);
bb.clear(); bb.clear();
// Get the one valid datagram // Get the one valid datagram
dc.configureBlocking(false);
while (sa == null) while (sa == null)
sa = dc.receive(bb); sa = dc.receive(bb);
sa = null; sa = null;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册