fix[channel]: wrong channel object was used

This commit is contained in:
godotg
2022-12-23 20:42:39 +08:00
parent 4cec1a0574
commit 91393207e5
3 changed files with 1 additions and 13 deletions
@@ -52,8 +52,6 @@ public abstract class AbstractServer<C extends Channel> extends ChannelInitializ
protected ChannelFuture channelFuture;
protected Channel channel;
public AbstractServer(HostAndPort host) {
this.hostAddress = host.getHost();
this.port = host.getPort();
@@ -91,7 +89,6 @@ public abstract class AbstractServer<C extends Channel> extends ChannelInitializ
// 异步
channelFuture = bootstrap.bind(hostAddress, port);
channelFuture.syncUninterruptibly();
channel = channelFuture.channel();
allServers.add(this);
@@ -111,14 +108,6 @@ public abstract class AbstractServer<C extends Channel> extends ChannelInitializ
logger.warn(e.getMessage(), e);
}
}
if (channel != null) {
try {
channel.close();
} catch (Exception e) {
logger.warn(e.getMessage(), e);
}
}
}
public synchronized static void shutdownAllServers() {
@@ -32,7 +32,7 @@ public class TcpServer extends AbstractServer<SocketChannel> {
}
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
protected void initChannel(SocketChannel channel) throws Exception {
channel.pipeline().addLast(new IdleStateHandler(0, 0, 180));
channel.pipeline().addLast(new ServerIdleHandler());
channel.pipeline().addLast(new TcpCodecHandler());
@@ -57,7 +57,6 @@ public class UdpServer extends AbstractServer<Channel> {
// 异步
channelFuture = bootstrap.bind(hostAddress, port);
channelFuture.syncUninterruptibly();
channel = channelFuture.channel();
allServers.add(this);