Mercurial > hg > RemoteEditor > REPSessionManager
changeset 267:c513cf1ce9cc
call handle.cancel() on socket channel close.
fix unterminated read() on closed channel.
on socket channel close, key.isreadable() and read() will return -1
we should throw IOException in this case.
author | kono |
---|---|
date | Thu, 11 Sep 2008 14:39:32 +0900 |
parents | 4a02c7f26794 |
children | b69d22dbc6f1 |
files | rep/REPCommandPacker.java rep/SessionManager.java rep/handler/REPHandler.java rep/handler/REPHandlerDoWaiting.java rep/handler/REPHandlerImpl.java rep/handler/REPHandlerInMerge.java |
diffstat | 6 files changed, 29 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/rep/REPCommandPacker.java Thu Sep 11 14:18:22 2008 +0900 +++ b/rep/REPCommandPacker.java Thu Sep 11 14:39:32 2008 +0900 @@ -89,7 +89,7 @@ throw new IOException(); } 下のwhileループで OK ? */ while(header.remaining()>0){ - sc.read(header); + if (sc.read(header)<0) throw new IOException(); } // 壊れたパケットに対してはブロックする可能性あり まぁTCPだしいいか? header.rewind(); // position = 0 @@ -112,7 +112,7 @@ throw new IOException(); }*/ while(textBuffer.remaining()>0){ - sc.read(textBuffer); + if (sc.read(textBuffer)<0) throw new IOException(); } textBuffer.rewind();
--- a/rep/SessionManager.java Thu Sep 11 14:18:22 2008 +0900 +++ b/rep/SessionManager.java Thu Sep 11 14:39:32 2008 +0900 @@ -3,6 +3,7 @@ import java.io.IOException; import java.net.InetSocketAddress; +import java.nio.channels.ClosedChannelException; import java.nio.channels.SelectionKey; import java.util.Iterator; import java.util.LinkedList; @@ -128,8 +129,15 @@ }else if(key.isReadable()){ REPHandler handler = (REPHandler)(key.attachment()); - handler.handle(key); - + try { + handler.handle(key); + } catch (ClosedChannelException x) { + key.cancel(); + handler.cancel(); + } catch (IOException x) { + key.cancel(); + handler.cancel(); + } } } }
--- a/rep/handler/REPHandler.java Thu Sep 11 14:18:22 2008 +0900 +++ b/rep/handler/REPHandler.java Thu Sep 11 14:39:32 2008 +0900 @@ -7,4 +7,6 @@ public interface REPHandler { void handle(REPSelectionKey<REPCommand> key)throws IOException; + void cancel(); + }
--- a/rep/handler/REPHandlerDoWaiting.java Thu Sep 11 14:18:22 2008 +0900 +++ b/rep/handler/REPHandlerDoWaiting.java Thu Sep 11 14:39:32 2008 +0900 @@ -14,4 +14,9 @@ } + public void cancel() { + // TODO Auto-generated method stub + + } + }