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 e46ba9e8de
commit 95576d6559
3 changed files with 18 additions and 5 deletions

View File

@ -177,7 +177,7 @@ public class ChunkedWriteHandler
} }
currentWrite.fail(cause); currentWrite.fail(cause);
} else { } else {
currentWrite.promise.setSuccess(); currentWrite.success();
} }
closeInput(in); closeInput(in);
} catch (Exception e) { } catch (Exception e) {
@ -278,7 +278,8 @@ public class ChunkedWriteHandler
@Override @Override
public void operationComplete(ChannelFuture future) throws Exception { public void operationComplete(ChannelFuture future) throws Exception {
pendingWrites.decrementAndGet(); pendingWrites.decrementAndGet();
currentWrite.promise.setSuccess(); currentWrite.progress();
currentWrite.success();
closeInput(chunks); 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() { void progress() {
progress ++; progress ++;
if (promise instanceof ChannelProgressivePromise) { if (promise instanceof ChannelProgressivePromise) {

View File

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

View File

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