Skip to content

Commit

Permalink
Simplify logic in chunked replicated content
Browse files Browse the repository at this point in the history
  • Loading branch information
martinfurmanski committed Jun 11, 2018
1 parent 39b7412 commit f413f3b
Showing 1 changed file with 5 additions and 10 deletions.
Expand Up @@ -87,16 +87,14 @@ public ByteBuf readChunk( ChannelHandlerContext ctx ) throws IOException
@Override
public ByteBuf readChunk( ByteBufAllocator allocator ) throws IOException
{
if ( isEndOfInput() )
if ( endOfInput )
{
return null;
}
// assume this is the last chunk
boolean lastChunk = true;
ByteBuf buffer = allocator.buffer( chunkSize );
try
{
buffer.writeBoolean( lastChunk );
buffer.writerIndex( 1 ); // space for endOfInput marker
if ( progress() == 0 )
{
// extra metadata on first chunk
Expand All @@ -105,14 +103,11 @@ public ByteBuf readChunk( ByteBufAllocator allocator ) throws IOException
}
if ( !byteBufAwareMarshal.encode( buffer ) )
{
this.endOfInput = true;
}
if ( isEndOfInput() != lastChunk )
{
// status changed after writing to buffer.
buffer.setBoolean( 0, isEndOfInput() );
endOfInput = true;
}
progress += buffer.readableBytes();
assert progress > 0; // logic relies on this
buffer.setBoolean( 0, endOfInput );
return buffer;
}
catch ( Throwable e )
Expand Down

0 comments on commit f413f3b

Please sign in to comment.