2003-09-25 Michael Koch <konqueror@gmx.de>
* gnu/java/nio/DatagramChannelImpl.java (DatagramChannelImpl): Made class final. (blocking): Made private. (socket): Made it a NIODatagramSocket and private. (DatagramChannelImpl): create NIODatagramSocket instead of DatagramSocket. (implConfigureBlocking): Set socket timeout. (connect): Check that channel is not closed. (write): Implemented. (write): Rewritten. (read): Implemented. (read): Rewritten. (receive): Implemented. (send): Implemented. * gnu/java/nio/SelectionKeyImpl.java (readyOps): Made private. (interestOps): Made private. (impl): Made private. (ch): Made private. (readyOps): Check if selection key is valid. (interestOps): Likewise. * gnu/java/nio/SelectorImpl.java (closed): Removed. (keys): Made private. (selected): Made private. (finalize): New method. (implCloseSelector): Rewritten. (keys): Return unmodifiable Set. (deregisterCancelledKeys): Fixed typo in method name. * gnu/java/nio/SocketChannelImpl.java (SocketChannelImpl): Made class final. (socket): Made it a NIOSocket and private. (blocking): Made private. (connected): Made private. (connectionPending): New member variable. (SocketChannelImpl): New implementation. (finalizer): Use isConnected(). (connect): Rewritten. (finishConnect): Throws IOException, implemented. (isConnectionPending): Return connectionPending. (read): Rewritten. (write): Rewritten. * gnu/java/nio/NIOConstants.java: New file. * Makefile.am (ordinary_java_source_files): Added gnu/java/nio/NIOConstants.java. * Makefile.in: Regenerated. From-SVN: r71769
This commit is contained in:
parent
131b9f3dcd
commit
21e69789dd
8 changed files with 439 additions and 85 deletions
|
@ -1,5 +1,5 @@
|
|||
/* SelectorImpl.java --
|
||||
Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
Copyright (C) 2002, 2003 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
|
@ -37,6 +37,7 @@ exception statement from your version. */
|
|||
|
||||
package gnu.java.nio;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.ClosedSelectorException;
|
||||
import java.nio.channels.SelectableChannel;
|
||||
import java.nio.channels.SelectionKey;
|
||||
|
@ -44,14 +45,15 @@ import java.nio.channels.Selector;
|
|||
import java.nio.channels.spi.AbstractSelectableChannel;
|
||||
import java.nio.channels.spi.AbstractSelector;
|
||||
import java.nio.channels.spi.SelectorProvider;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
public class SelectorImpl extends AbstractSelector
|
||||
{
|
||||
boolean closed = false;
|
||||
Set keys, selected, canceled;
|
||||
private Set keys;
|
||||
private Set selected;
|
||||
|
||||
public SelectorImpl (SelectorProvider provider)
|
||||
{
|
||||
|
@ -59,12 +61,23 @@ public class SelectorImpl extends AbstractSelector
|
|||
|
||||
keys = new HashSet ();
|
||||
selected = new HashSet ();
|
||||
canceled = new HashSet ();
|
||||
}
|
||||
|
||||
public Set keys ()
|
||||
protected void finalize() throws Throwable
|
||||
{
|
||||
return keys;
|
||||
close();
|
||||
}
|
||||
|
||||
protected final void implCloseSelector()
|
||||
throws IOException
|
||||
{
|
||||
// FIXME: We surely need to do more here.
|
||||
wakeup();
|
||||
}
|
||||
|
||||
public final Set keys()
|
||||
{
|
||||
return Collections.unmodifiableSet (keys);
|
||||
}
|
||||
|
||||
public int selectNow ()
|
||||
|
@ -120,10 +133,8 @@ public class SelectorImpl extends AbstractSelector
|
|||
|
||||
public int select (long timeout)
|
||||
{
|
||||
if (closed)
|
||||
{
|
||||
throw new ClosedSelectorException ();
|
||||
}
|
||||
if (!isOpen())
|
||||
throw new ClosedSelectorException ();
|
||||
|
||||
if (keys == null)
|
||||
{
|
||||
|
@ -132,7 +143,7 @@ public class SelectorImpl extends AbstractSelector
|
|||
|
||||
int ret = 0;
|
||||
|
||||
deregisterCanceledKeys ();
|
||||
deregisterCancelledKeys();
|
||||
|
||||
// Set only keys with the needed interest ops into the arrays.
|
||||
int[] read = getFDsAsArray (SelectionKey.OP_READ | SelectionKey.OP_ACCEPT);
|
||||
|
@ -202,7 +213,7 @@ public class SelectorImpl extends AbstractSelector
|
|||
key.readyOps (key.interestOps () & ops);
|
||||
}
|
||||
|
||||
deregisterCanceledKeys ();
|
||||
deregisterCancelledKeys();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -226,14 +237,9 @@ public class SelectorImpl extends AbstractSelector
|
|||
selected.add (k);
|
||||
}
|
||||
|
||||
protected void implCloseSelector ()
|
||||
private void deregisterCancelledKeys ()
|
||||
{
|
||||
closed = true;
|
||||
}
|
||||
|
||||
private void deregisterCanceledKeys ()
|
||||
{
|
||||
Iterator it = canceled.iterator ();
|
||||
Iterator it = cancelledKeys().iterator();
|
||||
|
||||
while (it.hasNext ())
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue