diff options
| author | Michael Koch <konqueror@gmx.de> | 2002-11-18 11:26:03 +0000 |
|---|---|---|
| committer | Michael Koch <konqueror@gmx.de> | 2002-11-18 11:26:03 +0000 |
| commit | f917ebf14cd0e07719f74ea00d25f5f6e6d645df (patch) | |
| tree | d2aa94bdf9d6d0f1670d47afc3fcf0d7a7476666 /gnu/java/nio/SelectorImpl.java | |
| parent | 49332699dc0c10b9010523a749400f2a8aab3de2 (diff) | |
| download | classpath-f917ebf14cd0e07719f74ea00d25f5f6e6d645df.tar.gz | |
2002-11-18 Michael Koch <konqueror@gmx.de>
* gnu/java/nio/SelectorImpl.java
(select): Throww exception when selector is closed,
reinitialize counter before reusing it.
(implCloseSelector): Implemented.
(register): Added support for ServerSocketChannelImpl.
* gnu/java/nio/ServerSocketChannelImpl.java
(ServerSocketChannelImpl): Create server socket.
* gnu/java/nio/SocketChannelImpl.java: Reformated.
* java/net/ServerSocket.java
(ServerSocket): Create unbound socket.
* java/nio/channels/ClosedChannelException.java: Documentation added.
* java/nio/channels/ClosedSelectorException.java: New file.
Diffstat (limited to 'gnu/java/nio/SelectorImpl.java')
| -rw-r--r-- | gnu/java/nio/SelectorImpl.java | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/gnu/java/nio/SelectorImpl.java b/gnu/java/nio/SelectorImpl.java index 0df173bea..14cfe9a19 100644 --- a/gnu/java/nio/SelectorImpl.java +++ b/gnu/java/nio/SelectorImpl.java @@ -37,6 +37,7 @@ exception statement from your version. */ package gnu.java.nio; +import java.nio.channels.ClosedSelectorException; import java.nio.channels.SelectableChannel; import java.nio.channels.SelectionKey; import java.nio.channels.Selector; @@ -49,6 +50,7 @@ import java.util.Set; public class SelectorImpl extends AbstractSelector { + boolean closed = false; Set keys, selected, canceled; public SelectorImpl (SelectorProvider provider) @@ -65,6 +67,7 @@ public class SelectorImpl extends AbstractSelector { return select (1); } + public int select () { return select (Long.MAX_VALUE); @@ -81,6 +84,11 @@ public class SelectorImpl extends AbstractSelector public int select (long timeout) { + if (closed) + { + throw new ClosedSelectorException (); + } + if (keys == null) { return 0; @@ -102,6 +110,8 @@ public class SelectorImpl extends AbstractSelector } int ret = java_do_select (read, write, except, timeout); + + i = 0; it = keys.iterator (); while (it.hasNext ()) @@ -149,6 +159,7 @@ public class SelectorImpl extends AbstractSelector protected void implCloseSelector () { + closed = true; } protected SelectionKey register (SelectableChannel ch, int ops, Object att) @@ -173,11 +184,18 @@ public class SelectorImpl extends AbstractSelector if (ch instanceof SocketChannelImpl) { - SocketChannelImpl fc = (SocketChannelImpl) ch; - SelectionKeyImpl impl = new SelectionKeyImpl (ch, this, fc.fd); + SocketChannelImpl sc = (SocketChannelImpl) ch; + SelectionKeyImpl impl = new SelectionKeyImpl (ch, this, sc.fd); add (impl); return impl; } + else if (ch instanceof ServerSocketChannelImpl) + { + ServerSocketChannelImpl ssc = (ServerSocketChannelImpl) ch; + SelectionKeyImpl impl = new SelectionKeyImpl (ch, this, ssc.fd); + add (impl); + return impl; + } else { System.err.println ("INTERNAL ERROR, no known channel type"); |
