# HG changeset patch # User kono # Date 1220182746 -32400 # Node ID 168dd841be5116722ba7efc7fd152c64363e2fb9 # Parent f9b1a9ba1a737af7bce73cceb8b1a178fd43725d selected key Interator fix. diff -r f9b1a9ba1a73 -r 168dd841be51 rep/channel/REPSelectionKey.java --- a/rep/channel/REPSelectionKey.java Sun Aug 31 19:49:35 2008 +0900 +++ b/rep/channel/REPSelectionKey.java Sun Aug 31 20:39:06 2008 +0900 @@ -31,10 +31,12 @@ public SelectableChannel channel() { if (REPServerSocketChannel.isSimulation) return key.channel(); if (key.isAcceptable()) { + //System.err.println("Accept selectionKey.channel = "+key.channel()); SelectableChannel sc = key.channel(); SelectableChannel rsc = REPSocketChannel.channels.get(sc); return rsc; } else if (key.isReadable()) { + //System.err.println("Read selectionKey.channel = "+key.channel()); SelectableChannel sc = key.channel(); SelectableChannel rsc = REPSocketChannel.channels.get(sc); return rsc; @@ -46,11 +48,13 @@ public SelectableChannel channel(REPPack

packer) { if (REPServerSocketChannel.isSimulation) return key.channel(); if (key.isAcceptable()) { + //System.err.println("AcceptP selectionKey.channel = "+key.channel()); SelectableChannel sc = key.channel(); SelectableChannel rsc = REPSocketChannel.channels.get(sc); if (rsc!=null) return rsc; return new REPServerSocketChannel

(key.channel(),packer); } else if (key.isReadable()) { + //System.err.println("ReadP selectionKey.channel = "+key.channel()); SelectableChannel sc = key.channel(); SelectableChannel rsc = REPSocketChannel.channels.get(sc); if (rsc!=null) return rsc; @@ -91,10 +95,9 @@ ServerSocketChannel ssc = (ServerSocketChannel)key.channel(); if (ssc==null) return null; SocketChannel ss = (SocketChannel)ssc.accept(); + //System.err.println("Accept in SelectionKey "+ss); if (ss==null) return null; - REPSocketChannel

rsc = (REPSocketChannel

)REPSocketChannel.channels.get(ss); - if (rsc!=null) return rsc; - return new REPSocketChannel

(ss,pack); + return new REPSocketChannel(ss, pack); } diff -r f9b1a9ba1a73 -r 168dd841be51 rep/channel/REPSelector.java --- a/rep/channel/REPSelector.java Sun Aug 31 19:49:35 2008 +0900 +++ b/rep/channel/REPSelector.java Sun Aug 31 20:39:06 2008 +0900 @@ -8,6 +8,7 @@ import java.nio.channels.spi.AbstractSelector; import java.nio.channels.spi.SelectorProvider; import java.util.HashSet; +import java.util.Iterator; import java.util.Set; @@ -77,9 +78,13 @@ public Set> selectedKeys1() { Set keys = selector.selectedKeys(); + //System.err.println("Selected keys = "+keys); HashSet> newKeys = new HashSet>(); - for(SelectionKey k: keys) { + + for (Iterator it = keys.iterator();it.hasNext(); ) { + SelectionKey k = it.next(); newKeys.add(new REPSelectionKey

(k,this)); + it.remove(); } return newKeys; } diff -r f9b1a9ba1a73 -r 168dd841be51 rep/channel/REPSocketChannel.java --- a/rep/channel/REPSocketChannel.java Sun Aug 31 19:49:35 2008 +0900 +++ b/rep/channel/REPSocketChannel.java Sun Aug 31 20:39:06 2008 +0900 @@ -32,6 +32,7 @@ public static void addChannel(SelectableChannel sc,SelectableChannel rc) { channels.put(sc, rc); + System.err.println("add Channel "+channels); } public void close1() throws IOException { @@ -74,11 +75,6 @@ } - public SelectionKey register(REPSelector

sel, int ops, Object att) throws ClosedChannelException { - return sc.register(sel.selector, ops, att); - } - - @Override public int validOps() { return sc.validOps(); @@ -139,6 +135,11 @@ return sc.connect(semaIP); } + public SelectionKey register(REPSelector

sel, int ops, Object att) throws ClosedChannelException { + return sc.register(sel.selector, ops, att); + } + + public SelectionKey register1(REPSelector

sel, int ops, Object att) throws ClosedChannelException {