- Removed unnecessary 'closed' flag and redundant close() calls, etc.
This commit is contained in:
Trustin Lee 2012-07-08 15:12:15 +09:00
parent 3fff8ce1d6
commit bf62add6c7

View File

@ -27,7 +27,6 @@ import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousCloseException;
import java.nio.channels.AsynchronousSocketChannel; import java.nio.channels.AsynchronousSocketChannel;
import java.nio.channels.ClosedChannelException; import java.nio.channels.ClosedChannelException;
import java.nio.channels.CompletionHandler; import java.nio.channels.CompletionHandler;
@ -66,7 +65,6 @@ public class AioSocketChannel extends AbstractAioChannel implements SocketChanne
}; };
private final AioSocketChannelConfig config; private final AioSocketChannelConfig config;
private boolean closed;
private boolean flushing; private boolean flushing;
public AioSocketChannel() { public AioSocketChannel() {
@ -155,10 +153,7 @@ public class AioSocketChannel extends AbstractAioChannel implements SocketChanne
@Override @Override
protected void doClose() throws Exception { protected void doClose() throws Exception {
if (!closed) { javaChannel().close();
closed = true;
javaChannel().close();
}
} }
@Override @Override
@ -204,9 +199,6 @@ public class AioSocketChannel extends AbstractAioChannel implements SocketChanne
// Stop flushing if disconnected. // Stop flushing if disconnected.
if (!channel.isActive()) { if (!channel.isActive()) {
if (!empty) {
channel.notifyFlushFutures(new ClosedChannelException());
}
return; return;
} }
@ -223,20 +215,14 @@ public class AioSocketChannel extends AbstractAioChannel implements SocketChanne
@Override @Override
protected void failed0(Throwable cause, AioSocketChannel channel) { protected void failed0(Throwable cause, AioSocketChannel channel) {
if (cause instanceof AsynchronousCloseException) {
channel.closed = true;
}
channel.notifyFlushFutures(cause); channel.notifyFlushFutures(cause);
channel.pipeline().fireExceptionCaught(cause); channel.pipeline().fireExceptionCaught(cause);
if (cause instanceof IOException) {
channel.unsafe().close(channel.unsafe().voidFuture()); ByteBuf buf = channel.pipeline().outboundByteBuffer();
} else { if (!buf.readable()) {
ByteBuf buf = channel.pipeline().outboundByteBuffer(); buf.discardReadBytes();
if (!buf.readable()) {
buf.discardReadBytes();
}
} }
// Allow to have the next write pending // Allow to have the next write pending
channel.flushing = false; channel.flushing = false;
} }
@ -268,19 +254,17 @@ public class AioSocketChannel extends AbstractAioChannel implements SocketChanne
} }
} catch (Throwable t) { } catch (Throwable t) {
if (t instanceof ClosedChannelException) {
channel.closed = true;
}
if (read) { if (read) {
read = false; read = false;
pipeline.fireInboundBufferUpdated(); pipeline.fireInboundBufferUpdated();
} }
pipeline.fireExceptionCaught(t); if (!(t instanceof ClosedChannelException)) {
pipeline.fireExceptionCaught(t);
if (t instanceof IOException) { if (t instanceof IOException) {
channel.unsafe().close(channel.unsafe().voidFuture()); channel.unsafe().close(channel.unsafe().voidFuture());
}
} }
} finally { } finally {
if (read) { if (read) {
@ -298,12 +282,11 @@ public class AioSocketChannel extends AbstractAioChannel implements SocketChanne
@Override @Override
protected void failed0(Throwable t, AioSocketChannel channel) { protected void failed0(Throwable t, AioSocketChannel channel) {
if (t instanceof ClosedChannelException) { if (t instanceof ClosedChannelException) {
channel.closed = true;
// TODO: This seems wrong!
return; return;
} }
channel.pipeline().fireExceptionCaught(t); channel.pipeline().fireExceptionCaught(t);
if (t instanceof IOException) { if (t instanceof IOException) {
channel.unsafe().close(channel.unsafe().voidFuture()); channel.unsafe().close(channel.unsafe().voidFuture());
} else { } else {
@ -326,9 +309,6 @@ public class AioSocketChannel extends AbstractAioChannel implements SocketChanne
@Override @Override
protected void failed0(Throwable exc, AioSocketChannel channel) { protected void failed0(Throwable exc, AioSocketChannel channel) {
if (exc instanceof AsynchronousCloseException) {
channel.closed = true;
}
((AsyncUnsafe) channel.unsafe()).connectFailed(exc); ((AsyncUnsafe) channel.unsafe()).connectFailed(exc);
} }
} }