mirror of
https://github.com/corda/corda.git
synced 2025-06-15 05:38:14 +00:00
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:
@ -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);
|
||||
|
Reference in New Issue
Block a user