mirror of
https://github.com/corda/corda.git
synced 2025-01-19 11:16:54 +00:00
various code cleanups, bug fixes, and compatibility fixes in NIO code
This commit is contained in:
parent
3a208edbbc
commit
6cddd10e0a
@ -575,6 +575,13 @@ Java_java_nio_channels_SocketSelector_natDoSocketSelect(JNIEnv *e, jclass,
|
||||
timeval time = { interval / 1000, (interval % 1000) * 1000 };
|
||||
int r = ::select(max + 1, &(s->read), &(s->write), &(s->except), &time);
|
||||
|
||||
if (r < 0) {
|
||||
if (errno != EINTR) {
|
||||
throwIOException(e);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
if (FD_ISSET(s->control.writer(), &(s->write)) or
|
||||
FD_ISSET(s->control.writer(), &(s->except)))
|
||||
@ -618,11 +625,6 @@ Java_java_nio_channels_SocketSelector_natDoSocketSelect(JNIEnv *e, jclass,
|
||||
}
|
||||
}
|
||||
|
||||
if (r < 0) {
|
||||
if (errno != EINTR) {
|
||||
throwIOException(e);
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,7 @@ public abstract class SelectableChannel implements Channel {
|
||||
public SelectionKey register(Selector selector, int interestOps,
|
||||
Object attachment)
|
||||
{
|
||||
SelectionKey key = new SelectionKey
|
||||
(this, selector, interestOps, attachment);
|
||||
key = new SelectionKey(this, selector, interestOps, attachment);
|
||||
selector.add(key);
|
||||
return key;
|
||||
}
|
||||
@ -34,7 +33,6 @@ public abstract class SelectableChannel implements Channel {
|
||||
|
||||
public void close() throws IOException {
|
||||
if (key != null) {
|
||||
key.selector().remove(key);
|
||||
key = null;
|
||||
}
|
||||
}
|
||||
|
@ -36,8 +36,9 @@ public class SelectionKey {
|
||||
return interestOps;
|
||||
}
|
||||
|
||||
public void interestOps(int v) {
|
||||
public SelectionKey interestOps(int v) {
|
||||
this.interestOps = v;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int readyOps() {
|
||||
|
@ -40,7 +40,7 @@ public abstract class Selector {
|
||||
|
||||
public abstract boolean isOpen();
|
||||
|
||||
public abstract void wakeup();
|
||||
public abstract Selector wakeup();
|
||||
|
||||
public abstract int select(long interval) throws IOException;
|
||||
|
||||
|
@ -44,7 +44,7 @@ public class SocketChannel extends SelectableChannel
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
if (! isOpen()) {
|
||||
if (isOpen()) {
|
||||
super.close();
|
||||
closeSocket();
|
||||
}
|
||||
|
@ -14,15 +14,10 @@ import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
class SocketSelector extends Selector {
|
||||
private static final boolean IsWin32;
|
||||
protected long state;
|
||||
protected final Object lock = new Object();
|
||||
protected boolean woken = false;
|
||||
|
||||
static {
|
||||
IsWin32 = false;
|
||||
}
|
||||
|
||||
public SocketSelector() {
|
||||
state = natInit();
|
||||
}
|
||||
@ -31,7 +26,7 @@ class SocketSelector extends Selector {
|
||||
return state != 0;
|
||||
}
|
||||
|
||||
public void wakeup() {
|
||||
public Selector wakeup() {
|
||||
synchronized (lock) {
|
||||
if (! woken) {
|
||||
woken = true;
|
||||
@ -39,6 +34,7 @@ class SocketSelector extends Selector {
|
||||
natWakeup(state);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
private boolean clearWoken() {
|
||||
@ -64,14 +60,14 @@ class SocketSelector extends Selector {
|
||||
SelectionKey key = it.next();
|
||||
SocketChannel c = (SocketChannel)key.channel();
|
||||
int socket = c.socketFD();
|
||||
if (! c.isOpen()) {
|
||||
if (c.isOpen()) {
|
||||
key.readyOps(0);
|
||||
max = natSelectUpdateInterestSet
|
||||
(socket, key.interestOps(), state, max);
|
||||
} else {
|
||||
natSelectClearAll(socket, state);
|
||||
it.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
key.readyOps(0);
|
||||
max = natSelectUpdateInterestSet(socket, key.interestOps(), state, max);
|
||||
}
|
||||
|
||||
int r = natDoSocketSelect(state, max, interval);
|
||||
|
Loading…
Reference in New Issue
Block a user