Avoid socket write when the buffer is empty

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2021-11-24 15:51:45 +01:00
parent 7889400e5b
commit b637cd3059

View File

@ -141,6 +141,8 @@ public final class BinaryBuffer {
}
public boolean writeChannel(WritableByteChannel channel) throws IOException {
if (readerOffset == writerOffset)
return true; // Nothing to write
var writeBuffer = nioBuffer.slice(readerOffset, writerOffset - readerOffset);
final int count = channel.write(writeBuffer);
if (count == -1) {