Correctly write single ByteBuf with memoryAddress
Motivation:
While optimize gathering writes I introduced a bug when writing single ByteBuf that have a memoryAddress. This regression was introduced by 88bd6e7a93
.
Modifications:
Correctly use the writerIndex as argument when call Native.writeAddress(...)
Result:
No more corruption while write single buffers.
This commit is contained in:
parent
ca0571cc9d
commit
30295138fe
@ -116,8 +116,9 @@ public final class EpollSocketChannel extends AbstractEpollChannel implements So
|
|||||||
if (buf.hasMemoryAddress()) {
|
if (buf.hasMemoryAddress()) {
|
||||||
long memoryAddress = buf.memoryAddress();
|
long memoryAddress = buf.memoryAddress();
|
||||||
int readerIndex = buf.readerIndex();
|
int readerIndex = buf.readerIndex();
|
||||||
|
int writerIndex = buf.writerIndex();
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int localFlushedAmount = Native.writeAddress(fd, memoryAddress, readerIndex, readableBytes);
|
int localFlushedAmount = Native.writeAddress(fd, memoryAddress, readerIndex, writerIndex);
|
||||||
if (localFlushedAmount > 0) {
|
if (localFlushedAmount > 0) {
|
||||||
writtenBytes += localFlushedAmount;
|
writtenBytes += localFlushedAmount;
|
||||||
if (writtenBytes == readableBytes) {
|
if (writtenBytes == readableBytes) {
|
||||||
@ -125,7 +126,6 @@ public final class EpollSocketChannel extends AbstractEpollChannel implements So
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
readerIndex += localFlushedAmount;
|
readerIndex += localFlushedAmount;
|
||||||
readableBytes -= localFlushedAmount;
|
|
||||||
} else {
|
} else {
|
||||||
// Returned EAGAIN need to set EPOLLOUT
|
// Returned EAGAIN need to set EPOLLOUT
|
||||||
setEpollOut();
|
setEpollOut();
|
||||||
|
Loading…
Reference in New Issue
Block a user