From aa536ddb0b2a7c6a9253af191b123019524ed8a3 Mon Sep 17 00:00:00 2001 From: Alexey Plotnik Date: Mon, 13 Feb 2017 01:47:42 +1000 Subject: [PATCH] Update progress during upload large bodies Motivation: org.asynchttpclient.netty.request.body.BodyChunkedInput does not update progress member, it stays zero whole time. Thus org.asynchttpclient.handler.onContentWriteProgress#onContentWriteProgress receives zeroes in ammount and current parameters. Users sees data is being sent but has no information about exact amount of data has been written to channel. Modifications: org.asynchttpclient.netty.request.body.BodyChunkedInput was modified to update progress. org.asynchttpclient.netty.request.WriteProgressListener was modified to ignore zero progress. It happens due to non-blocking nature of network writes. We just ignore callbacks when there was no progress at all. Result: Progress is updated each time bytes are phisically written to channel. Callbacks are triggered with actual amount of data written. --- .../asynchttpclient/netty/request/WriteProgressListener.java | 4 +++- .../asynchttpclient/netty/request/body/BodyChunkedInput.java | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/client/src/main/java/org/asynchttpclient/netty/request/WriteProgressListener.java b/client/src/main/java/org/asynchttpclient/netty/request/WriteProgressListener.java index 6abe955e0e..7fc3ec4a63 100755 --- a/client/src/main/java/org/asynchttpclient/netty/request/WriteProgressListener.java +++ b/client/src/main/java/org/asynchttpclient/netty/request/WriteProgressListener.java @@ -45,7 +45,9 @@ public void operationProgressed(ChannelProgressiveFuture f, long progress, long if (total < 0) { total = expectedTotal; } - progressAsyncHandler.onContentWriteProgress(progress - lastLastProgress, progress, total); + if (progress != lastLastProgress) { + progressAsyncHandler.onContentWriteProgress(progress - lastLastProgress, progress, total); + } } } } diff --git a/client/src/main/java/org/asynchttpclient/netty/request/body/BodyChunkedInput.java b/client/src/main/java/org/asynchttpclient/netty/request/body/BodyChunkedInput.java index b208308fe8..b1f2462442 100755 --- a/client/src/main/java/org/asynchttpclient/netty/request/body/BodyChunkedInput.java +++ b/client/src/main/java/org/asynchttpclient/netty/request/body/BodyChunkedInput.java @@ -57,6 +57,7 @@ public ByteBuf readChunk(ByteBufAllocator alloc) throws Exception { ByteBuf buffer = alloc.buffer(chunkSize); Body.BodyState state = body.transferTo(buffer); + progress += buffer.writerIndex(); switch (state) { case STOP: endOfInput = true;