Fail all pending writes on channelClosed(..). See #305

This commit is contained in:
norman 2012-05-04 10:24:28 +02:00 committed by Trustin Lee
parent d1e6328102
commit d308fa8fe1

View File

@ -1230,6 +1230,48 @@ public class SslHandler extends FrameDecoder
super.channelConnected(ctx, e);
}
/**
* Loop over all the pending writes and fail them.
*
* See <a href="https://github.com/netty/netty/issues/305">#305</a> for more details.
*/
@Override
public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
Throwable cause = null;
synchronized (pendingUnencryptedWrites) {
for (;;) {
PendingWrite pw = pendingUnencryptedWrites.poll();
if (pw == null) {
break;
}
if (cause == null) {
cause = new ClosedChannelException();
}
pw.future.setFailure(cause);
}
for (;;) {
MessageEvent ev = pendingEncryptedWrites.poll();
if (ev == null) {
break;
}
if (cause == null) {
cause = new ClosedChannelException();
}
ev.getFuture().setFailure(cause);
}
}
if (cause != null) {
fireExceptionCaught(ctx, cause);
}
super.channelClosed(ctx, e);
}
private final class SSLEngineInboundCloseFuture extends DefaultChannelFuture {
public SSLEngineInboundCloseFuture() {
super(null, true);