diff --git a/classpath/java-nio.cpp b/classpath/java-nio.cpp index e5a0e345ff..6c3fb14ee5 100644 --- a/classpath/java-nio.cpp +++ b/classpath/java-nio.cpp @@ -626,7 +626,17 @@ Java_java_nio_channels_SocketSelector_natDoSocketSelect(JNIEnv *e, jclass, } #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); if (r < 0) { diff --git a/classpath/java/nio/channels/Selector.java b/classpath/java/nio/channels/Selector.java index 021f267f17..7716db60e9 100644 --- a/classpath/java/nio/channels/Selector.java +++ b/classpath/java/nio/channels/Selector.java @@ -42,7 +42,11 @@ public abstract class Selector { public abstract Selector wakeup(); + public abstract int selectNow() throws IOException; + public abstract int select(long interval) throws IOException; + public abstract int select() throws IOException; + public abstract void close(); } diff --git a/classpath/java/nio/channels/SocketSelector.java b/classpath/java/nio/channels/SocketSelector.java index 587340a508..79d01d8594 100644 --- a/classpath/java/nio/channels/SocketSelector.java +++ b/classpath/java/nio/channels/SocketSelector.java @@ -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 { + if (interval < 0) throw new IllegalArgumentException(); + + return doSelect(interval); + } + + public int doSelect(long interval) throws IOException { selectedKeys.clear(); if (clearWoken()) return 0;