mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-08 16:32:07 +01:00
Add threshold for flushing
This commit is contained in:
parent
19a84bcddd
commit
effca76196
@ -60,6 +60,7 @@ public class NettyPlayerConnection extends PlayerConnection {
|
||||
private UUID bungeeUuid;
|
||||
private PlayerSkin bungeeSkin;
|
||||
|
||||
private static final int FLUSH_SIZE = 20000;
|
||||
private final ByteBuf tickBuffer = Unpooled.directBuffer();
|
||||
|
||||
public NettyPlayerConnection(@NotNull SocketChannel channel) {
|
||||
@ -164,6 +165,7 @@ public class NettyPlayerConnection extends PlayerConnection {
|
||||
synchronized (tickBuffer) {
|
||||
final ByteBuf body = framedPacket.getBody();
|
||||
tickBuffer.writeBytes(body, body.readerIndex(), body.readableBytes());
|
||||
preventiveWrite();
|
||||
}
|
||||
return;
|
||||
} else if (message instanceof ServerPacket) {
|
||||
@ -171,12 +173,14 @@ public class NettyPlayerConnection extends PlayerConnection {
|
||||
final ByteBuf buffer = PacketUtils.createFramedPacket(serverPacket, true);
|
||||
synchronized (tickBuffer) {
|
||||
tickBuffer.writeBytes(buffer);
|
||||
preventiveWrite();
|
||||
}
|
||||
buffer.release();
|
||||
return;
|
||||
} else if (message instanceof ByteBuf) {
|
||||
synchronized (tickBuffer) {
|
||||
tickBuffer.writeBytes((ByteBuf) message);
|
||||
preventiveWrite();
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -196,6 +200,12 @@ public class NettyPlayerConnection extends PlayerConnection {
|
||||
}
|
||||
}
|
||||
|
||||
private void preventiveWrite() {
|
||||
if (tickBuffer.writerIndex() > FLUSH_SIZE) {
|
||||
writeWaitingPackets();
|
||||
}
|
||||
}
|
||||
|
||||
private void writeWaitingPackets() {
|
||||
synchronized (tickBuffer) {
|
||||
final ByteBuf copy = tickBuffer.copy();
|
||||
|
Loading…
Reference in New Issue
Block a user