Fix a bug where discardReadBytes() doesn't adjust markers

.. if buffer is empty
This commit is contained in:
Trustin Lee 2012-07-10 14:23:31 +09:00
parent 170a04fc72
commit 917ed5173e

View File

@ -146,16 +146,17 @@ public abstract class AbstractByteBuf implements ByteBuf {
return;
}
if (readerIndex == writerIndex) {
clear();
return;
if (readerIndex != writerIndex) {
setBytes(0, this, readerIndex, writerIndex - readerIndex);
writerIndex -= readerIndex;
markedReaderIndex = Math.max(markedReaderIndex - readerIndex, 0);
markedWriterIndex = Math.max(markedWriterIndex - readerIndex, 0);
readerIndex = 0;
} else {
markedReaderIndex = Math.max(markedReaderIndex - readerIndex, 0);
markedWriterIndex = Math.max(markedWriterIndex - readerIndex, 0);
writerIndex = readerIndex = 0;
}
setBytes(0, this, readerIndex, writerIndex - readerIndex);
writerIndex -= readerIndex;
markedReaderIndex = Math.max(markedReaderIndex - readerIndex, 0);
markedWriterIndex = Math.max(markedWriterIndex - readerIndex, 0);
readerIndex = 0;
}
@Override