mirror of
https://github.com/corda/corda.git
synced 2025-02-08 12:00:35 +00:00
Merge branch 'master' of oss.readytalk.com:/var/local/git/avian
This commit is contained in:
commit
88c582868c
@ -36,6 +36,7 @@
|
|||||||
|
|
||||||
#define java_nio_channels_SelectionKey_OP_READ 1L
|
#define java_nio_channels_SelectionKey_OP_READ 1L
|
||||||
#define java_nio_channels_SelectionKey_OP_WRITE 4L
|
#define java_nio_channels_SelectionKey_OP_WRITE 4L
|
||||||
|
#define java_nio_channels_SelectionKey_OP_CONNECT 8L
|
||||||
#define java_nio_channels_SelectionKey_OP_ACCEPT 16L
|
#define java_nio_channels_SelectionKey_OP_ACCEPT 16L
|
||||||
|
|
||||||
#ifdef PLATFORM_WINDOWS
|
#ifdef PLATFORM_WINDOWS
|
||||||
@ -151,6 +152,17 @@ init(JNIEnv* e, sockaddr_in* address, jstring hostString, jint port)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool
|
||||||
|
einProgress(int error)
|
||||||
|
{
|
||||||
|
#ifdef PLATFORM_WINDOWS
|
||||||
|
return error == WSAEINPROGRESS
|
||||||
|
or error == WSAEWOULDBLOCK;
|
||||||
|
#else
|
||||||
|
return error == EINPROGRESS;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
einProgress()
|
einProgress()
|
||||||
{
|
{
|
||||||
@ -371,6 +383,25 @@ Java_java_nio_channels_SocketChannel_natDoConnect(JNIEnv *e,
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" JNIEXPORT jboolean JNICALL
|
||||||
|
Java_java_nio_channels_SocketChannel_natFinishConnect(JNIEnv *e,
|
||||||
|
jclass,
|
||||||
|
jint socket)
|
||||||
|
{
|
||||||
|
int error;
|
||||||
|
socklen_t size = sizeof(int);
|
||||||
|
int r = getsockopt(socket, SOL_SOCKET, SO_ERROR,
|
||||||
|
reinterpret_cast<char*>(&error), &size);
|
||||||
|
if (r != 0 or size != sizeof(int)) {
|
||||||
|
throwIOException(e);
|
||||||
|
} else if (einProgress(error)) {
|
||||||
|
return false;
|
||||||
|
} else if (error != 0) {
|
||||||
|
throwIOException(e);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" JNIEXPORT jint JNICALL
|
extern "C" JNIEXPORT jint JNICALL
|
||||||
Java_java_nio_channels_SocketChannel_natRead(JNIEnv *e,
|
Java_java_nio_channels_SocketChannel_natRead(JNIEnv *e,
|
||||||
jclass,
|
jclass,
|
||||||
@ -626,7 +657,8 @@ Java_java_nio_channels_SocketSelector_natSelectUpdateInterestSet(JNIEnv *,
|
|||||||
FD_CLR(static_cast<unsigned>(socket), &(s->read));
|
FD_CLR(static_cast<unsigned>(socket), &(s->read));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (interest & java_nio_channels_SelectionKey_OP_WRITE) {
|
if (interest & (java_nio_channels_SelectionKey_OP_WRITE |
|
||||||
|
java_nio_channels_SelectionKey_OP_CONNECT)) {
|
||||||
FD_SET(static_cast<unsigned>(socket), &(s->write));
|
FD_SET(static_cast<unsigned>(socket), &(s->write));
|
||||||
if (max < socket) max = socket;
|
if (max < socket) max = socket;
|
||||||
} else {
|
} else {
|
||||||
@ -748,10 +780,16 @@ Java_java_nio_channels_SocketSelector_natUpdateReadySet(JNIEnv *, jclass,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((interest & java_nio_channels_SelectionKey_OP_WRITE)
|
if (FD_ISSET(socket, &(s->write))) {
|
||||||
and FD_ISSET(socket, &(s->write))) {
|
if (interest & java_nio_channels_SelectionKey_OP_WRITE) {
|
||||||
ready |= java_nio_channels_SelectionKey_OP_WRITE;
|
ready |= java_nio_channels_SelectionKey_OP_WRITE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (interest & java_nio_channels_SelectionKey_OP_CONNECT) {
|
||||||
|
ready |= java_nio_channels_SelectionKey_OP_CONNECT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ready;
|
return ready;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,8 +13,8 @@ package java.nio.channels;
|
|||||||
public class SelectionKey {
|
public class SelectionKey {
|
||||||
public static final int OP_READ = 1 << 0;
|
public static final int OP_READ = 1 << 0;
|
||||||
public static final int OP_WRITE = 1 << 2;
|
public static final int OP_WRITE = 1 << 2;
|
||||||
|
public static final int OP_CONNECT = 1 << 3;
|
||||||
public static final int OP_ACCEPT = 1 << 4;
|
public static final int OP_ACCEPT = 1 << 4;
|
||||||
// public static final int OP_CONNECT = 1 << 3;
|
|
||||||
|
|
||||||
private final SelectableChannel channel;
|
private final SelectableChannel channel;
|
||||||
private final Selector selector;
|
private final Selector selector;
|
||||||
@ -57,6 +57,10 @@ public class SelectionKey {
|
|||||||
return (readyOps & OP_WRITE) != 0;
|
return (readyOps & OP_WRITE) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isConnectable() {
|
||||||
|
return (readyOps & OP_CONNECT) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isAcceptable() {
|
public boolean isAcceptable() {
|
||||||
return (readyOps & OP_ACCEPT) != 0;
|
return (readyOps & OP_ACCEPT) != 0;
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,10 @@ public class SocketChannel extends SelectableChannel
|
|||||||
return connected;
|
return connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean finishConnect() throws IOException {
|
||||||
|
return natFinishConnect(socket);
|
||||||
|
}
|
||||||
|
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
if (isOpen()) {
|
if (isOpen()) {
|
||||||
super.close();
|
super.close();
|
||||||
@ -126,6 +130,8 @@ public class SocketChannel extends SelectableChannel
|
|||||||
|
|
||||||
private static native int natDoConnect(String host, int port, boolean blocking, boolean[] connected)
|
private static native int natDoConnect(String host, int port, boolean blocking, boolean[] connected)
|
||||||
throws IOException;
|
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)
|
||||||
throws IOException;
|
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user