List r = new ArrayList();
List w = new ArrayList();
List e = new ArrayList();
for (Iterator i = selector.selectedKeys().iterator(); i.hasNext(); ) {
SelectionKey key = (SelectionKey) i.next();
if ((key.interestOps() & key.readyOps()
& (SelectionKey.OP_READ|SelectionKey.OP_ACCEPT|SelectionKey.OP_CONNECT)) != 0) {
r.add(key.attachment());
pending.remove(key.attachment());
}
if ((key.interestOps() & key.readyOps() & (SelectionKey.OP_WRITE)) != 0) {
w.add(key.attachment());
}
}
r.addAll(pending);
r.addAll(unselectable_reads);
w.addAll(unselectable_writes);
// make all sockets blocking as configured again
for (Iterator i = selector.keys().iterator(); i.hasNext(); ) {
SelectionKey key = (SelectionKey) i.next();
SelectableChannel channel = key.channel();
synchronized(channel.blockingLock()) {
RubyIO originalIO = (RubyIO) TypeConverter.convertToType(
(IRubyObject) key.attachment(), runtime.getIO(),
MethodIndex.TO_IO, "to_io");
boolean blocking = originalIO.getBlocking();
key.cancel();
channel.configureBlocking(blocking);
}
}
selector.close();