TCP_NODELAY

This commit is contained in:
artem 2020-06-28 23:31:45 +05:00
parent 6a6309377f
commit f8dceb51b4

View File

@ -17,8 +17,6 @@ import java.net.InetSocketAddress;
public class NettyServer { public class NettyServer {
private final PacketProcessor packetProcessor;
private final EventLoopGroup boss, worker; private final EventLoopGroup boss, worker;
private final ServerBootstrap bootstrap; private final ServerBootstrap bootstrap;
@ -28,8 +26,6 @@ public class NettyServer {
private int port; private int port;
public NettyServer(PacketProcessor packetProcessor) { public NettyServer(PacketProcessor packetProcessor) {
this.packetProcessor = packetProcessor;
Class<? extends ServerChannel> channel; Class<? extends ServerChannel> channel;
if (Epoll.isAvailable()) { if (Epoll.isAvailable()) {
@ -49,12 +45,15 @@ public class NettyServer {
bootstrap.channel(channel); bootstrap.channel(channel);
bootstrap.childHandler(new ChannelInitializer<SocketChannel>() { bootstrap.childHandler(new ChannelInitializer<SocketChannel>() {
protected void initChannel(SocketChannel socketChannel) { protected void initChannel(SocketChannel ch) {
socketChannel.pipeline().addLast(new NettyDecoder()); ChannelConfig config = ch.config();
socketChannel.pipeline().addLast(new ClientChannel(packetProcessor)); config.setOption(ChannelOption.TCP_NODELAY, true);
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new NettyDecoder());
pipeline.addLast(new ClientChannel(packetProcessor));
} }
}); });
} }
public void start(String address, int port) { public void start(String address, int port) {