Ensure operationProgressed is invoked even on completion

- Fixes #1809
This commit is contained in:
Trustin Lee 2013-09-05 18:36:48 +09:00
parent 845a7c5753
commit ad0c456209
3 changed files with 18 additions and 5 deletions

View File

@ -177,7 +177,7 @@ public class ChunkedWriteHandler
}
currentWrite.fail(cause);
} else {
currentWrite.promise.setSuccess();
currentWrite.success();
}
closeInput(in);
} catch (Exception e) {
@ -278,7 +278,8 @@ public class ChunkedWriteHandler
@Override
public void operationComplete(ChannelFuture future) throws Exception {
pendingWrites.decrementAndGet();
currentWrite.promise.setSuccess();
currentWrite.progress();
currentWrite.success();
closeInput(chunks);
}
});
@ -354,6 +355,14 @@ public class ChunkedWriteHandler
}
}
void success() {
if (promise instanceof ChannelProgressivePromise) {
// Now we know what the total is.
((ChannelProgressivePromise) promise).tryProgress(progress, progress);
}
promise.setSuccess();
}
void progress() {
progress ++;
if (promise instanceof ChannelProgressivePromise) {

View File

@ -187,11 +187,12 @@ public abstract class AbstractNioByteChannel extends AbstractNioChannel {
}
}
in.progress(flushedAmount);
if (done) {
in.remove();
} else {
// Did not write completely.
in.progress(flushedAmount);
setOpWrite();
break;
}
@ -215,11 +216,12 @@ public abstract class AbstractNioByteChannel extends AbstractNioChannel {
}
}
in.progress(flushedAmount);
if (done) {
in.remove();
} else {
// Did not write completely.
in.progress(flushedAmount);
setOpWrite();
break;
}

View File

@ -279,13 +279,15 @@ public class NioSocketChannel extends AbstractNioByteChannel implements io.netty
final int readableBytes = buf.writerIndex() - readerIndex;
if (readableBytes < writtenBytes) {
in.progress(readableBytes);
in.remove();
writtenBytes -= readableBytes;
} else if (readableBytes > writtenBytes) {
buf.readerIndex(readerIndex + (int) writtenBytes);
in.progress(writtenBytes);
break;
} else { // readable == writtenBytes
} else { // readableBytes == writtenBytes
in.progress(readableBytes);
in.remove();
break;
}