Do not fallback to waiting list

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2022-04-02 23:35:11 +02:00
parent ff8dd0cdaa
commit 7a371fe616

View File

@ -415,18 +415,18 @@ public class PlayerSocketConnection extends PlayerConnection {
public void flushSync() throws IOException {
final SocketChannel channel = this.channel;
final List<BinaryBuffer> waitingBuffers = this.waitingBuffers;
if (!channel.isConnected()) throw new ClosedChannelException();
// Fast exit if the tick buffer can be reused
if (waitingBuffers.isEmpty() && tickBuffer.getPlain().writeChannel(channel))
return;
// Write as much as possible from the waiting list
Iterator<BinaryBuffer> iterator = waitingBuffers.iterator();
while (iterator.hasNext()) {
BinaryBuffer waitingBuffer = iterator.next();
if (!waitingBuffer.writeChannel(channel)) break;
iterator.remove();
PooledBuffers.add(waitingBuffer);
if (waitingBuffers.isEmpty()) {
tickBuffer.getPlain().writeChannel(channel);
} else {
// Write as much as possible from the waiting list
Iterator<BinaryBuffer> iterator = waitingBuffers.iterator();
while (iterator.hasNext()) {
BinaryBuffer waitingBuffer = iterator.next();
if (!waitingBuffer.writeChannel(channel)) break;
iterator.remove();
PooledBuffers.add(waitingBuffer);
}
}
}