/* AbstractSelectableChannel.java
- Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
public abstract class AbstractSelectableChannel extends SelectableChannel
{
- private int registered;
private boolean blocking = true;
private Object LOCK = new Object();
private SelectorProvider provider;
- private LinkedList keys;
+ private LinkedList keys = new LinkedList();
/**
* Initializes the channel
protected AbstractSelectableChannel (SelectorProvider provider)
{
this.provider = provider;
- this.keys = new LinkedList();
}
/**
{
synchronized (blockingLock())
{
- implConfigureBlocking(blocking);
- this.blocking = blocking;
+ if (this.blocking != blocking)
+ {
+ implConfigureBlocking(blocking);
+ this.blocking = blocking;
+ }
}
return this;
*/
public final SelectionKey keyFor(Selector selector)
{
+ if (! isOpen())
+ return null;
+
try
{
- return register (selector, 0, null);
+ synchronized(blockingLock())
+ {
+ return locate (selector);
+ }
}
catch (Exception e)
{
private SelectionKey locate (Selector selector)
{
- if (keys == null)
- return null;
-
ListIterator it = keys.listIterator ();
while (it.hasNext ())
return null;
}
- private void add (SelectionKey key)
- {
- keys.add (key);
- }
-
/**
* Registers this channel with the given selector, returning a selection key.
*
if (key != null)
{
- key.attach (att);
+ if (att != null)
+ key.attach (att);
}
else
{
key = selector.register (this, ops, att);
if (key != null)
- add (key);
+ addSelectionKey (key);
}
}
return key;
}
+
+ void addSelectionKey(SelectionKey key)
+ {
+ keys.add(key);
+ }
+
+ // This method gets called by AbstractSelector.deregister().
+ void removeSelectionKey(SelectionKey key)
+ {
+ keys.remove(key);
+ }
}