mirror of
https://github.com/corda/corda.git
synced 2025-01-31 16:35:43 +00:00
implement Selector.selectNow() and select()
This commit is contained in:
parent
77f1bddce2
commit
29858a5299
@ -626,7 +626,17 @@ Java_java_nio_channels_SocketSelector_natDoSocketSelect(JNIEnv *e, jclass,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
timeval time = { interval / 1000, (interval % 1000) * 1000 };
|
timeval time;
|
||||||
|
if (interval > 0) {
|
||||||
|
time.tv_sec = interval / 1000;
|
||||||
|
time.tv_usec = (interval % 1000) * 1000;
|
||||||
|
} else if (interval < 0) {
|
||||||
|
time.tv_sec = 0;
|
||||||
|
time.tv_usec = 0;
|
||||||
|
} else {
|
||||||
|
time.tv_sec = INT32_MAX;
|
||||||
|
time.tv_usec = 0;
|
||||||
|
}
|
||||||
int r = ::select(max + 1, &(s->read), &(s->write), &(s->except), &time);
|
int r = ::select(max + 1, &(s->read), &(s->write), &(s->except), &time);
|
||||||
|
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
|
@ -42,7 +42,11 @@ public abstract class Selector {
|
|||||||
|
|
||||||
public abstract Selector wakeup();
|
public abstract Selector wakeup();
|
||||||
|
|
||||||
|
public abstract int selectNow() throws IOException;
|
||||||
|
|
||||||
public abstract int select(long interval) throws IOException;
|
public abstract int select(long interval) throws IOException;
|
||||||
|
|
||||||
|
public abstract int select() throws IOException;
|
||||||
|
|
||||||
public abstract void close();
|
public abstract void close();
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,21 @@ class SocketSelector extends Selector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized int selectNow() throws IOException {
|
||||||
|
return doSelect(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized int select() throws IOException {
|
||||||
|
return doSelect(0);
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized int select(long interval) throws IOException {
|
public synchronized int select(long interval) throws IOException {
|
||||||
|
if (interval < 0) throw new IllegalArgumentException();
|
||||||
|
|
||||||
|
return doSelect(interval);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int doSelect(long interval) throws IOException {
|
||||||
selectedKeys.clear();
|
selectedKeys.clear();
|
||||||
|
|
||||||
if (clearWoken()) return 0;
|
if (clearWoken()) return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user