diff options
author | Michael Koch <konqueror@gmx.de> | 2003-10-09 17:34:10 +0000 |
---|---|---|
committer | Michael Koch <mkoch@gcc.gnu.org> | 2003-10-09 17:34:10 +0000 |
commit | 4e3cb200a543c0a52b4a8ec8f1a1518bfcb08ce2 (patch) | |
tree | 3d255b674b1d9f300d842c3696c2bef6cd9f7869 /libjava | |
parent | 93d046861d42e9779905f7db3c575923290eedf2 (diff) | |
download | gcc-4e3cb200a543c0a52b4a8ec8f1a1518bfcb08ce2.zip gcc-4e3cb200a543c0a52b4a8ec8f1a1518bfcb08ce2.tar.gz gcc-4e3cb200a543c0a52b4a8ec8f1a1518bfcb08ce2.tar.bz2 |
2003-10-09 Michael Koch <konqueror@gmx.de>
* java/nio/channels/spi/AbstractSelectableChannel.java
(registered): Made private.
(blocking): Likewise.
(LOCK): Likewise.
(provider): Likewise.
(keys): Made it a private LinkedList.
(AbstractSelectableChannel): Initialize keys.
(isRegistered): New implementation.
(locate): Rewritten.
(register): Rewritten.
* java/nio/channels/spi/AbstractSelectionKey.java
(ok): Removed.
(cancelled): New member variable.
(cancel): Rewritten.
(isValid): Rewritten.
* java/nio/channels/spi/AbstractSelector.java:
Some methods moved.
(closed): Make private.
(provider): Likewise.
(cancelledKeys): New member variable.
(AbstractSelector): Initialize cancelledKeys.
(cancelKey): New method.
From-SVN: r72275
Diffstat (limited to 'libjava')
-rw-r--r-- | libjava/ChangeLog | 25 | ||||
-rw-r--r-- | libjava/java/nio/channels/spi/AbstractSelectableChannel.java | 48 | ||||
-rw-r--r-- | libjava/java/nio/channels/spi/AbstractSelectionKey.java | 16 | ||||
-rw-r--r-- | libjava/java/nio/channels/spi/AbstractSelector.java | 41 |
4 files changed, 81 insertions, 49 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 0c6ec09..3523854 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,28 @@ +2003-10-09 Michael Koch <konqueror@gmx.de> + + * java/nio/channels/spi/AbstractSelectableChannel.java + (registered): Made private. + (blocking): Likewise. + (LOCK): Likewise. + (provider): Likewise. + (keys): Made it a private LinkedList. + (AbstractSelectableChannel): Initialize keys. + (isRegistered): New implementation. + (locate): Rewritten. + (register): Rewritten. + * java/nio/channels/spi/AbstractSelectionKey.java + (ok): Removed. + (cancelled): New member variable. + (cancel): Rewritten. + (isValid): Rewritten. + * java/nio/channels/spi/AbstractSelector.java: + Some methods moved. + (closed): Make private. + (provider): Likewise. + (cancelledKeys): New member variable. + (AbstractSelector): Initialize cancelledKeys. + (cancelKey): New method. + 2003-10-09 Tom Tromey <tromey@redhat.com> * java/lang/ClassLoader.java (setSigners): Implemented. diff --git a/libjava/java/nio/channels/spi/AbstractSelectableChannel.java b/libjava/java/nio/channels/spi/AbstractSelectableChannel.java index b13bb4a..b027b03 100644 --- a/libjava/java/nio/channels/spi/AbstractSelectableChannel.java +++ b/libjava/java/nio/channels/spi/AbstractSelectableChannel.java @@ -1,5 +1,5 @@ /* AbstractSelectableChannel.java - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -48,11 +48,11 @@ import java.util.ListIterator; public abstract class AbstractSelectableChannel extends SelectableChannel { - int registered; - boolean blocking = true; - Object LOCK = new Object (); - SelectorProvider provider; - List keys; + private int registered; + private boolean blocking = true; + private Object LOCK = new Object(); + private SelectorProvider provider; + private LinkedList keys; /** * Initializes the channel @@ -60,6 +60,7 @@ public abstract class AbstractSelectableChannel extends SelectableChannel protected AbstractSelectableChannel (SelectorProvider provider) { this.provider = provider; + this.keys = new LinkedList(); } /** @@ -122,7 +123,7 @@ public abstract class AbstractSelectableChannel extends SelectableChannel */ public final boolean isRegistered() { - return registered > 0; + return !keys.isEmpty(); } /** @@ -154,28 +155,21 @@ public abstract class AbstractSelectableChannel extends SelectableChannel if (keys == null) return null; - SelectionKey k = null; ListIterator it = keys.listIterator (); while (it.hasNext ()) { - k = (SelectionKey) it.next (); - if (k.selector () == selector) - { - return k; - } + SelectionKey key = (SelectionKey) it.next(); + + if (key.selector() == selector) + return key; } - return k; + return null; } private void add (SelectionKey key) { - if (keys == null) - { - keys = new LinkedList (); - } - keys.add (key); } @@ -190,26 +184,26 @@ public abstract class AbstractSelectableChannel extends SelectableChannel if (!isOpen ()) throw new ClosedChannelException(); - SelectionKey k = null; + SelectionKey key = null; AbstractSelector selector = (AbstractSelector) selin; synchronized (LOCK) { - k = locate (selector); + key = locate (selector); - if (k != null) + if (key != null) { - k.attach (att); + key.attach (att); } else { - k = selector.register (this, ops, att); + key = selector.register (this, ops, att); - if (k != null) - add (k); + if (key != null) + add (key); } } - return k; + return key; } } diff --git a/libjava/java/nio/channels/spi/AbstractSelectionKey.java b/libjava/java/nio/channels/spi/AbstractSelectionKey.java index 01ea4f3..0cd5ee1 100644 --- a/libjava/java/nio/channels/spi/AbstractSelectionKey.java +++ b/libjava/java/nio/channels/spi/AbstractSelectionKey.java @@ -1,5 +1,5 @@ /* AbstractSelectionKey.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -45,7 +45,7 @@ import java.nio.channels.SelectionKey; public abstract class AbstractSelectionKey extends SelectionKey { - boolean ok = true; + private boolean cancelled = false; /** * Initializes the key. @@ -59,10 +59,12 @@ public abstract class AbstractSelectionKey */ public final void cancel () { - if (ok) - selector ().selectedKeys ().add (this); - - ok = false; + if (isValid()) + { + // FIXME: implement this. + //selector().cancelledKeys().add (this); + cancelled = true; + } } /** @@ -70,6 +72,6 @@ public abstract class AbstractSelectionKey */ public final boolean isValid () { - return ok; + return !cancelled; } } diff --git a/libjava/java/nio/channels/spi/AbstractSelector.java b/libjava/java/nio/channels/spi/AbstractSelector.java index 160cdc0..58ce0c8 100644 --- a/libjava/java/nio/channels/spi/AbstractSelector.java +++ b/libjava/java/nio/channels/spi/AbstractSelector.java @@ -1,5 +1,5 @@ /* AbstractSelector.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -42,11 +42,13 @@ import java.io.IOException; import java.nio.channels.SelectionKey; import java.nio.channels.Selector; import java.util.Set; +import java.util.HashSet; public abstract class AbstractSelector extends Selector { - boolean closed = false; - SelectorProvider provider; + private boolean closed = false; + private SelectorProvider provider; + private HashSet cancelledKeys; /** * Initializes the slector. @@ -54,16 +56,10 @@ public abstract class AbstractSelector extends Selector protected AbstractSelector (SelectorProvider provider) { this.provider = provider; + this.cancelledKeys = new HashSet(); } /** - * Marks the beginning of an I/O operation that might block indefinitely. - */ - protected final void begin () - { - } - - /** * Closes the channel. * * @exception IOException If an error occurs @@ -73,8 +69,8 @@ public abstract class AbstractSelector extends Selector if (closed) return; + implCloseSelector(); closed = true; - implCloseSelector (); } /** @@ -85,11 +81,16 @@ public abstract class AbstractSelector extends Selector return ! closed; } - protected final void deregister (AbstractSelectionKey key) + /** + * Marks the beginning of an I/O operation that might block indefinitely. + */ + protected final void begin() { - cancelledKeys ().remove (key); } - + + /** + * Marks the end of an I/O operation that might block indefinitely. + */ protected final void end() { } @@ -101,7 +102,12 @@ public abstract class AbstractSelector extends Selector protected final Set cancelledKeys() { - return null; + return cancelledKeys; + } + + final void cancelKey (AbstractSelectionKey key) + { + cancelledKeys.remove (key); } /** @@ -111,4 +117,9 @@ public abstract class AbstractSelector extends Selector protected abstract SelectionKey register (AbstractSelectableChannel ch, int ops, Object att); + + protected final void deregister (AbstractSelectionKey key) + { + // FIXME + } } |