mirror of
https://github.com/Minestom/Minestom.git
synced 2024-09-24 20:42:39 +02:00
Avoid socket write when the buffer is empty
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
7889400e5b
commit
b637cd3059
@ -141,6 +141,8 @@ public final class BinaryBuffer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean writeChannel(WritableByteChannel channel) throws IOException {
|
public boolean writeChannel(WritableByteChannel channel) throws IOException {
|
||||||
|
if (readerOffset == writerOffset)
|
||||||
|
return true; // Nothing to write
|
||||||
var writeBuffer = nioBuffer.slice(readerOffset, writerOffset - readerOffset);
|
var writeBuffer = nioBuffer.slice(readerOffset, writerOffset - readerOffset);
|
||||||
final int count = channel.write(writeBuffer);
|
final int count = channel.write(writeBuffer);
|
||||||
if (count == -1) {
|
if (count == -1) {
|
||||||
|
Loading…
Reference in New Issue
Block a user