mirror of
https://github.com/Minestom/Minestom.git
synced 2025-03-13 07:09:51 +01:00
Enable tcpNoDelay + prevent memory leak on disconnection
This commit is contained in:
parent
6e18d2bcfe
commit
7e452cdd74
@ -65,8 +65,6 @@ public final class NettyServer {
|
||||
private final PacketProcessor packetProcessor;
|
||||
private final GlobalChannelTrafficShapingHandler globalTrafficHandler;
|
||||
|
||||
private boolean tcpNoDelay = false;
|
||||
|
||||
private EventLoopGroup boss, worker;
|
||||
private ServerBootstrap bootstrap;
|
||||
|
||||
@ -163,7 +161,7 @@ public final class NettyServer {
|
||||
bootstrap.childHandler(new ChannelInitializer<SocketChannel>() {
|
||||
protected void initChannel(@NotNull SocketChannel ch) {
|
||||
ChannelConfig config = ch.config();
|
||||
config.setOption(ChannelOption.TCP_NODELAY, tcpNoDelay);
|
||||
config.setOption(ChannelOption.TCP_NODELAY, true);
|
||||
config.setOption(ChannelOption.SO_SNDBUF, 262_144);
|
||||
config.setAllocator(ByteBufAllocator.DEFAULT);
|
||||
|
||||
@ -259,14 +257,6 @@ public final class NettyServer {
|
||||
return globalTrafficHandler;
|
||||
}
|
||||
|
||||
public boolean isTcpNoDelay() {
|
||||
return tcpNoDelay;
|
||||
}
|
||||
|
||||
public void setTcpNoDelay(boolean tcpNoDelay) {
|
||||
this.tcpNoDelay = tcpNoDelay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the server and the various services.
|
||||
*/
|
||||
|
@ -8,6 +8,7 @@ import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.network.ConnectionManager;
|
||||
import net.minestom.server.network.PacketProcessor;
|
||||
import net.minestom.server.network.netty.packet.InboundPacket;
|
||||
import net.minestom.server.network.player.NettyPlayerConnection;
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
@ -67,6 +68,11 @@ public class ClientChannel extends SimpleChannelInboundHandler<InboundPacket> {
|
||||
CONNECTION_MANAGER.removePlayer(playerConnection);
|
||||
}
|
||||
packetProcessor.removePlayerConnection(ctx);
|
||||
|
||||
// Release tick buffer
|
||||
if (playerConnection instanceof NettyPlayerConnection) {
|
||||
((NettyPlayerConnection) playerConnection).getTickBuffer().release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -356,6 +356,11 @@ public class NettyPlayerConnection extends PlayerConnection {
|
||||
this.serverPort = serverPort;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ByteBuf getTickBuffer() {
|
||||
return tickBuffer;
|
||||
}
|
||||
|
||||
public byte[] getNonce() {
|
||||
return nonce;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user