mirror of
https://github.com/corda/corda.git
synced 2025-04-07 11:27:01 +00:00
Merge commit 'origin/master' into wip
This commit is contained in:
commit
5967246b37
@ -355,6 +355,27 @@ Java_java_io_File_delete(JNIEnv* e, jclass, jstring path)
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_java_io_File_rename(JNIEnv* e, jclass, jstring old, jstring new_)
|
||||
{
|
||||
const char* oldChars = e->GetStringUTFChars(old, 0);
|
||||
const char* newChars = e->GetStringUTFChars(new_, 0);
|
||||
if (oldChars) {
|
||||
bool v;
|
||||
if (newChars) {
|
||||
v = rename(oldChars, newChars) == 0;
|
||||
|
||||
e->ReleaseStringUTFChars(new_, newChars);
|
||||
} else {
|
||||
v = false;
|
||||
}
|
||||
e->ReleaseStringUTFChars(old, oldChars);
|
||||
return v;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_java_io_File_isDirectory(JNIEnv* e, jclass, jstring path)
|
||||
{
|
||||
|
@ -36,6 +36,7 @@
|
||||
|
||||
#define java_nio_channels_SelectionKey_OP_READ 1L
|
||||
#define java_nio_channels_SelectionKey_OP_WRITE 4L
|
||||
#define java_nio_channels_SelectionKey_OP_CONNECT 8L
|
||||
#define java_nio_channels_SelectionKey_OP_ACCEPT 16L
|
||||
|
||||
#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
|
||||
einProgress()
|
||||
{
|
||||
@ -371,6 +383,25 @@ Java_java_nio_channels_SocketChannel_natDoConnect(JNIEnv *e,
|
||||
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
|
||||
Java_java_nio_channels_SocketChannel_natRead(JNIEnv *e,
|
||||
jclass,
|
||||
@ -521,15 +552,18 @@ class Pipe {
|
||||
if (setBlocking(e, pipe[0], false)) {
|
||||
setBlocking(e, pipe[1], false);
|
||||
}
|
||||
|
||||
open_ = true;
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
::close(pipe[0]);
|
||||
::close(pipe[1]);
|
||||
open_ = false;
|
||||
}
|
||||
|
||||
bool connected() {
|
||||
return true;
|
||||
return open_;
|
||||
}
|
||||
|
||||
int reader() {
|
||||
@ -542,6 +576,7 @@ class Pipe {
|
||||
|
||||
private:
|
||||
int pipe[2];
|
||||
bool open_;
|
||||
#endif
|
||||
};
|
||||
|
||||
@ -622,7 +657,8 @@ Java_java_nio_channels_SocketSelector_natSelectUpdateInterestSet(JNIEnv *,
|
||||
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));
|
||||
if (max < socket) max = socket;
|
||||
} else {
|
||||
@ -744,10 +780,16 @@ Java_java_nio_channels_SocketSelector_natUpdateReadySet(JNIEnv *, jclass,
|
||||
}
|
||||
}
|
||||
|
||||
if ((interest & java_nio_channels_SelectionKey_OP_WRITE)
|
||||
and FD_ISSET(socket, &(s->write))) {
|
||||
ready |= java_nio_channels_SelectionKey_OP_WRITE;
|
||||
if (FD_ISSET(socket, &(s->write))) {
|
||||
if (interest & 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;
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,12 @@ public class File {
|
||||
this(parent.getPath() + FileSeparator + child);
|
||||
}
|
||||
|
||||
public static native boolean rename(String old, String new_);
|
||||
|
||||
public boolean renameTo(File newName) {
|
||||
return rename(path, newName.path);
|
||||
}
|
||||
|
||||
private static native boolean isDirectory(String path);
|
||||
|
||||
public boolean isDirectory() {
|
||||
|
@ -231,11 +231,25 @@ public final class String
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
return this == o || (o instanceof String && compareTo((String) o) == 0);
|
||||
if (this == o) {
|
||||
return true;
|
||||
} else if (o instanceof String) {
|
||||
String s = (String) o;
|
||||
return s.length == length && compareTo(s) == 0;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean equalsIgnoreCase(String s) {
|
||||
return this == s || (s != null && compareToIgnoreCase(s) == 0);
|
||||
public boolean equalsIgnoreCase(String o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
} else if (o instanceof String) {
|
||||
String s = (String) o;
|
||||
return s.length == length && compareToIgnoreCase(s) == 0;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public int compareTo(String s) {
|
||||
|
@ -16,6 +16,8 @@ import java.nio.ByteBuffer;
|
||||
public abstract class SelectableChannel implements Channel {
|
||||
private SelectionKey key;
|
||||
|
||||
abstract int socketFD();
|
||||
|
||||
public abstract SelectableChannel configureBlocking(boolean v)
|
||||
throws IOException;
|
||||
|
||||
|
@ -13,8 +13,8 @@ package java.nio.channels;
|
||||
public class SelectionKey {
|
||||
public static final int OP_READ = 1 << 0;
|
||||
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_CONNECT = 1 << 3;
|
||||
|
||||
private final SelectableChannel channel;
|
||||
private final Selector selector;
|
||||
@ -57,6 +57,10 @@ public class SelectionKey {
|
||||
return (readyOps & OP_WRITE) != 0;
|
||||
}
|
||||
|
||||
public boolean isConnectable() {
|
||||
return (readyOps & OP_CONNECT) != 0;
|
||||
}
|
||||
|
||||
public boolean isAcceptable() {
|
||||
return (readyOps & OP_ACCEPT) != 0;
|
||||
}
|
||||
|
@ -23,6 +23,10 @@ public class ServerSocketChannel extends SelectableChannel {
|
||||
return new ServerSocketChannel();
|
||||
}
|
||||
|
||||
public int socketFD() {
|
||||
return channel.socketFD();
|
||||
}
|
||||
|
||||
public SelectableChannel configureBlocking(boolean v) throws IOException {
|
||||
return channel.configureBlocking(v);
|
||||
}
|
||||
|
@ -58,6 +58,10 @@ public class SocketChannel extends SelectableChannel
|
||||
return connected;
|
||||
}
|
||||
|
||||
public boolean finishConnect() throws IOException {
|
||||
return natFinishConnect(socket);
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
if (isOpen()) {
|
||||
super.close();
|
||||
@ -126,6 +130,8 @@ public class SocketChannel extends SelectableChannel
|
||||
|
||||
private static native int natDoConnect(String host, int port, boolean blocking, boolean[] connected)
|
||||
throws IOException;
|
||||
private static native boolean natFinishConnect(int socket)
|
||||
throws IOException;
|
||||
private static native int natRead(int socket, byte[] buffer, int offset, int length)
|
||||
throws IOException;
|
||||
private static native int natWrite(int socket, byte[] buffer, int offset, int length)
|
||||
|
@ -72,7 +72,7 @@ class SocketSelector extends Selector {
|
||||
it.hasNext();)
|
||||
{
|
||||
SelectionKey key = it.next();
|
||||
SocketChannel c = (SocketChannel)key.channel();
|
||||
SelectableChannel c = key.channel();
|
||||
int socket = c.socketFD();
|
||||
if (c.isOpen()) {
|
||||
key.readyOps(0);
|
||||
@ -88,7 +88,7 @@ class SocketSelector extends Selector {
|
||||
|
||||
if (r > 0) {
|
||||
for (SelectionKey key : keys) {
|
||||
SocketChannel c = (SocketChannel)key.channel();
|
||||
SelectableChannel c = key.channel();
|
||||
int socket = c.socketFD();
|
||||
int ready = natUpdateReadySet(socket, key.interestOps(), state);
|
||||
key.readyOps(ready);
|
||||
|
Loading…
x
Reference in New Issue
Block a user