diff --git a/src/com/wentch/redkale/net/AsyncConnection.java b/src/com/wentch/redkale/net/AsyncConnection.java index 9ecff75b5..560ecd791 100644 --- a/src/com/wentch/redkale/net/AsyncConnection.java +++ b/src/com/wentch/redkale/net/AsyncConnection.java @@ -38,7 +38,23 @@ public abstract class AsyncConnection implements AsynchronousByteChannel, AutoCl protected abstract void write(ByteBuffer[] srcs, int offset, int length, A attachment, CompletionHandler handler); - public abstract void dispose(); //同close, 只是去掉throws IOException + public void dispose() {//同close, 只是去掉throws IOException + try { + this.close(); + } catch (IOException io) { + } + } + + @Override + public void close() throws IOException { + if (attributes == null) return; + try { + for (Object obj : attributes.values()) { + if (obj instanceof AutoCloseable) ((AutoCloseable) obj).close(); + } + } catch (Exception io) { + } + } public void setAttribute(String name, Object value) { if (attributes == null) attributes = new HashMap<>(); @@ -173,19 +189,12 @@ public abstract class AsyncConnection implements AsynchronousByteChannel, AutoCl @Override public final void close() throws IOException { + super.close(); if (client) { channel.close(); } } - @Override - public void dispose() { - try { - this.close(); - } catch (IOException io) { - } - } - @Override public final boolean isOpen() { return channel.isOpen(); @@ -323,14 +332,6 @@ public abstract class AsyncConnection implements AsynchronousByteChannel, AutoCl } } - @Override - public void dispose() { - try { - this.close(); - } catch (IOException io) { - } - } - @Override public void read(ByteBuffer dst, A attachment, CompletionHandler handler) { try { @@ -373,6 +374,7 @@ public abstract class AsyncConnection implements AsynchronousByteChannel, AutoCl @Override public void close() throws IOException { + super.close(); this.socket.close(); } @@ -488,6 +490,7 @@ public abstract class AsyncConnection implements AsynchronousByteChannel, AutoCl @Override public final void close() throws IOException { + super.close(); channel.close(); } @@ -501,13 +504,6 @@ public abstract class AsyncConnection implements AsynchronousByteChannel, AutoCl return true; } - @Override - public void dispose() { - try { - this.close(); - } catch (IOException io) { - } - } } public static AsyncConnection create(final AsynchronousSocketChannel ch) {