Clean up
- Removed unnecessary 'closed' flag and redundant close() calls, etc.
This commit is contained in:
parent
3fff8ce1d6
commit
bf62add6c7
@ -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,11 +153,8 @@ public class AioSocketChannel extends AbstractAioChannel implements SocketChanne
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doClose() throws Exception {
|
protected void doClose() throws Exception {
|
||||||
if (!closed) {
|
|
||||||
closed = true;
|
|
||||||
javaChannel().close();
|
javaChannel().close();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isFlushPending() {
|
protected boolean isFlushPending() {
|
||||||
@ -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());
|
|
||||||
} else {
|
|
||||||
ByteBuf buf = channel.pipeline().outboundByteBuffer();
|
ByteBuf buf = channel.pipeline().outboundByteBuffer();
|
||||||
if (!buf.readable()) {
|
if (!buf.readable()) {
|
||||||
buf.discardReadBytes();
|
buf.discardReadBytes();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// Allow to have the next write pending
|
// Allow to have the next write pending
|
||||||
channel.flushing = false;
|
channel.flushing = false;
|
||||||
}
|
}
|
||||||
@ -268,20 +254,18 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(t instanceof ClosedChannelException)) {
|
||||||
pipeline.fireExceptionCaught(t);
|
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) {
|
||||||
pipeline.fireInboundBufferUpdated();
|
pipeline.fireInboundBufferUpdated();
|
||||||
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user