From 4dd462d0b501d15ec5b1adba2438d9d2a3c106cb Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Fri, 18 Jan 2013 07:03:55 +0100 Subject: [PATCH] [#907] Stop flush if one outboundbuffer was freed and do the same for inboundBufferUpdated if an inboundbuffer was freed --- .../channel/DefaultChannelHandlerContext.java | 22 +++++-------------- .../netty/channel/DefaultChannelPipeline.java | 2 ++ 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/transport/src/main/java/io/netty/channel/DefaultChannelHandlerContext.java b/transport/src/main/java/io/netty/channel/DefaultChannelHandlerContext.java index 2f1dabd245..39fcfc3dbc 100755 --- a/transport/src/main/java/io/netty/channel/DefaultChannelHandlerContext.java +++ b/transport/src/main/java/io/netty/channel/DefaultChannelHandlerContext.java @@ -1084,7 +1084,7 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements } catch (Throwable t) { pipeline.notifyHandlerException(t); } finally { - if (handler instanceof ChannelInboundByteHandler && !inboundByteBuffer().isFreed()) { + if (handler instanceof ChannelInboundByteHandler && !isInboundBufferFreed()) { try { ((ChannelInboundByteHandler) handler).discardInboundReadBytes(this); } catch (Throwable t) { @@ -1424,7 +1424,7 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements } catch (Throwable t) { pipeline.notifyHandlerException(t); } finally { - if (handler instanceof ChannelOutboundByteHandler) { + if (handler instanceof ChannelOutboundByteHandler && !isOutboundBufferFreed()) { try { ((ChannelOutboundByteHandler) handler).discardOutboundReadBytes(this); } catch (Throwable t) { @@ -1559,6 +1559,7 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements } void invokeFreeInboundBuffer() { + pipeline.inboundBufferFreed = true; EventExecutor executor = executor(); if (prev != null && executor.inEventLoop()) { invokeFreeInboundBuffer0(); @@ -1598,6 +1599,7 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements /** Invocation initiated by {@link #invokeFreeInboundBuffer0()} after freeing all inbound buffers. */ private void invokeFreeOutboundBuffer() { + pipeline.outboundBufferFreed = true; EventExecutor executor = executor(); if (executor.inEventLoop()) { invokeFreeOutboundBuffer0(); @@ -1648,23 +1650,11 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements } private boolean isInboundBufferFreed() { - if (hasInboundByteBuffer()) { - return inboundByteBuffer().isFreed(); - } - if (hasInboundMessageBuffer()) { - return inboundMessageBuffer().isFreed(); - } - return false; + return pipeline.inboundBufferFreed; } private boolean isOutboundBufferFreed() { - if (hasOutboundByteBuffer()) { - return outboundByteBuffer().isFreed(); - } - if (hasOutboundMessageBuffer()) { - return outboundMessageBuffer().isFreed(); - } - return false; + return pipeline.outboundBufferFreed; } private void validateFuture(ChannelFuture future) { diff --git a/transport/src/main/java/io/netty/channel/DefaultChannelPipeline.java b/transport/src/main/java/io/netty/channel/DefaultChannelPipeline.java index 6e68dfb7af..fee544b217 100755 --- a/transport/src/main/java/io/netty/channel/DefaultChannelPipeline.java +++ b/transport/src/main/java/io/netty/channel/DefaultChannelPipeline.java @@ -57,6 +57,8 @@ final class DefaultChannelPipeline implements ChannelPipeline { new IdentityHashMap(); private static final TailHandler TAIL_HANDLER = new TailHandler(); + volatile boolean inboundBufferFreed; + volatile boolean outboundBufferFreed; public DefaultChannelPipeline(Channel channel) { if (channel == null) {