[#2371] Fix data corruption caused by EpollSocketChannel when writing
Motivation: We sometimes see data corruption when writing to the EpollSocketChannel. Modifications: The problem was caused as we mixed writing via memory address and via ByteBuffer. This not works out pretty well because of how the position of the buffer is updated etc. To fix the problem we only write via ByteBuffer (this is true for normal and gathering writes). Before normal writes may write via the memory address and gathering writes always used the ByteBuffer. Result: Fix data-corruption which could happen on partial writes
This commit is contained in:
parent
ce3af65074
commit
9cf92b3999
@ -122,12 +122,8 @@ public final class EpollSocketChannel extends AbstractEpollChannel implements So
|
||||
int readerIndex = buf.readerIndex();
|
||||
int localFlushedAmount;
|
||||
if (buf.nioBufferCount() == 1) {
|
||||
if (buf.hasMemoryAddress()) {
|
||||
localFlushedAmount = Native.writeAddress(fd, buf.memoryAddress(), readerIndex, buf.writerIndex());
|
||||
} else {
|
||||
ByteBuffer nioBuf = buf.internalNioBuffer(readerIndex, readable);
|
||||
localFlushedAmount = Native.write(fd, nioBuf, nioBuf.position(), nioBuf.limit());
|
||||
}
|
||||
ByteBuffer nioBuf = buf.internalNioBuffer(readerIndex, readable);
|
||||
localFlushedAmount = Native.write(fd, nioBuf, nioBuf.position(), nioBuf.limit());
|
||||
} else {
|
||||
// backed by more then one buffer, do a gathering write...
|
||||
ByteBuffer[] nioBufs = buf.nioBuffers();
|
||||
|
Loading…
x
Reference in New Issue
Block a user