fix several blocking SocketChannel bugs

In java-nio.cpp, we can't use GetPrimitiveArrayCritical when reading
from or writing to blocking sockets since it may block the rest of the
VM indefinitely.

In SelectableChannel.java, we can't use a null test on
SelectableChannel.key to determine whether the channel is open since
it might never be registered with a Selector.  According to the Sun
documentation, a SelectableChannel is open as soon as it's created, so
that's what we now implement.
This commit is contained in:
Joel Dice
2010-06-04 15:37:22 -06:00
parent 74e282a3d3
commit b908f575d5
3 changed files with 56 additions and 20 deletions

View File

@ -92,7 +92,7 @@ public class SocketChannel extends SelectableChannel
byte[] array = b.array();
if (array == null) throw new NullPointerException();
int r = natRead(socket, array, b.arrayOffset() + b.position(), b.remaining());
int r = natRead(socket, array, b.arrayOffset() + b.position(), b.remaining(), blocking);
if (r > 0) {
b.position(b.position() + r);
}
@ -108,7 +108,7 @@ public class SocketChannel extends SelectableChannel
byte[] array = b.array();
if (array == null) throw new NullPointerException();
int w = natWrite(socket, array, b.arrayOffset() + b.position(), b.remaining());
int w = natWrite(socket, array, b.arrayOffset() + b.position(), b.remaining(), blocking);
if (w > 0) {
b.position(b.position() + w);
}
@ -139,9 +139,9 @@ public class SocketChannel extends SelectableChannel
throws IOException;
private static native boolean natFinishConnect(int socket)
throws IOException;
private static native int natRead(int socket, byte[] buffer, int offset, int length)
private static native int natRead(int socket, byte[] buffer, int offset, int length, boolean blocking)
throws IOException;
private static native int natWrite(int socket, byte[] buffer, int offset, int length)
private static native int natWrite(int socket, byte[] buffer, int offset, int length, boolean blocking)
throws IOException;
private static native void natThrowWriteError(int socket) throws IOException;
private static native void natCloseSocket(int socket);