Index: UDPSelectorHandler.java =================================================================== --- UDPSelectorHandler.java (revision 432) +++ UDPSelectorHandler.java (working copy) @@ -31,6 +31,7 @@ import java.net.SocketAddress; import java.net.SocketException; import java.nio.channels.DatagramChannel; +import java.nio.channels.SelectableChannel; import java.nio.channels.SelectionKey; import java.nio.channels.Selector; import java.util.Iterator; @@ -249,6 +250,14 @@ throw new IllegalStateException(NOT_SUPPORTED); } + public void closeChannel(SelectableChannel channel) { + try{ + channel.close(); + } catch (IOException ex){ + ; // LOG ME + } + } + //--------------- ConnectorInstanceHandler ----------------------------- @Override protected Callable getConnectorInstanceHandlerDelegate() { Index: DefaultSelectionKeyHandler.java =================================================================== --- DefaultSelectionKeyHandler.java (revision 434) +++ DefaultSelectionKeyHandler.java (working copy) @@ -66,11 +66,26 @@ */ protected long timeout = 30 * 1000L; + /** + * Associated SelectorHandler + */ + private SelectorHandler selectorHandler; public DefaultSelectionKeyHandler() { } + public DefaultSelectionKeyHandler(SelectorHandler selectorHandler) { + this.selectorHandler = selectorHandler; + } + /** + * Set associated SelectorHandler + */ + public void setSelectorHandler(SelectorHandler selectorHandler) { + this.selectorHandler = selectorHandler; + } + + /** * {@inheritDoc} */ public void process(SelectionKey key) { @@ -206,7 +221,11 @@ return; } - closeChannel(key.channel()); + if (selectorHandler != null) { + selectorHandler.closeChannel(key.channel()); + } else { + closeChannel(key.channel()); + } key.attach(null); key.cancel(); @@ -238,7 +257,6 @@ this.timeout = timeout; } - protected void closeChannel(SelectableChannel channel) { if (channel instanceof SocketChannel) { Socket socket = ((SocketChannel) channel).socket(); @@ -267,5 +285,5 @@ } catch (IOException ex){ ; // LOG ME } - } + } } Index: SelectorHandler.java =================================================================== --- SelectorHandler.java (revision 432) +++ SelectorHandler.java (working copy) @@ -228,4 +228,9 @@ * Return the ProtocolChainInstanceHandler */ public ProtocolChainInstanceHandler getProtocolChainInstanceHandler(); + + /** + * Closes SelectableChannel + */ + public void closeChannel(SelectableChannel channel); } Index: TCPSelectorHandler.java =================================================================== --- TCPSelectorHandler.java (revision 443) +++ TCPSelectorHandler.java (working copy) @@ -804,7 +804,37 @@ return instanceHandler; } - + /** + * {@inheritDoc} + */ + public void closeChannel(SelectableChannel channel) { + Socket socket = ((SocketChannel) channel).socket(); + + try { + if (!socket.isInputShutdown()) socket.shutdownInput(); + } catch (IOException ex){ + ; + } + + try { + if (!socket.isOutputShutdown()) socket.shutdownOutput(); + } catch (IOException ex){ + ; + } + + try{ + socket.close(); + } catch (IOException ex){ + ; + } + + try{ + channel.close(); + } catch (IOException ex){ + ; // LOG ME + } + } + //--------------- ConnectorInstanceHandler ----------------------------- /** * Return factory object, which knows how