Call ChunkedWriteHandler.flush() once again if tried when locked.

Force recursive call of ChunkedWriteHandler.flush() if another thread
tried to call it when lock was held.
Solves problem of lost resumeTransfer() call.
This commit is contained in:
Lukasz Osipiuk 2012-10-02 15:17:23 +02:00
parent 6ca523a754
commit 20509fb516

View File

@ -84,6 +84,7 @@ public class ChunkedWriteHandler
private volatile ChannelHandlerContext ctx;
private final AtomicBoolean flush = new AtomicBoolean(false);
private MessageEvent currentEvent;
private volatile boolean flushNeeded;
/**
* Continues to fetch the chunks from the input.
@ -187,9 +188,10 @@ public class ChunkedWriteHandler
boolean acquired = false;
final Channel channel = ctx.getChannel();
boolean suspend = false;
flushNeeded = true;
// use CAS to see if the have flush already running, if so we don't need to take futher actions
if (acquired = flush.compareAndSet(false, true)) {
flushNeeded = false;
try {
if (!channel.isConnected()) {
@ -297,7 +299,7 @@ public class ChunkedWriteHandler
}
if (acquired && (!channel.isConnected() || channel.isWritable() && !queue.isEmpty() && !suspend)) {
if (acquired && ((!channel.isConnected() || channel.isWritable() && !queue.isEmpty() && !suspend) || flushNeeded)) {
flush(ctx, fireNow);
}
}