From 5b8b9cab57c30be9c8c42ede79cd3eef949a1ea7 Mon Sep 17 00:00:00 2001 From: TheMode Date: Mon, 9 Aug 2021 02:05:51 +0200 Subject: [PATCH] Fix buffer not being emptied --- .../minestom/server/utils/binary/BinaryBuffer.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/minestom/server/utils/binary/BinaryBuffer.java b/src/main/java/net/minestom/server/utils/binary/BinaryBuffer.java index 96715f511..b4c4b5e0e 100644 --- a/src/main/java/net/minestom/server/utils/binary/BinaryBuffer.java +++ b/src/main/java/net/minestom/server/utils/binary/BinaryBuffer.java @@ -124,12 +124,15 @@ public final class BinaryBuffer { } public void writeChannel(WritableByteChannel channel) throws IOException { - final int count = channel.write(asByteBuffer(readerOffset, writerOffset)); - if (count == -1) { - // EOS - throw new IOException("Disconnected"); + var writeBuffer = asByteBuffer(readerOffset, writerOffset); + while (writeBuffer.position() != writeBuffer.limit()) { + final int count = channel.write(writeBuffer); + if (count == -1) { + // EOS + throw new IOException("Disconnected"); + } + this.readerOffset += count; } - this.readerOffset += count; } public void readChannel(ReadableByteChannel channel) throws IOException {