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