mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-15 10:15:59 +00:00
fix[channel]: wrong channel object was used
This commit is contained in:
1 parent
4cec1a0574
commit
91393207e5
3 files changed
+1
-13
No files matched your search
@@ -52,8 +52,6 @@ public abstract class AbstractServer<C extends Channel> extends ChannelInitializ
|
|||||||
|
|
||||||
protected ChannelFuture channelFuture;
|
protected ChannelFuture channelFuture;
|
||||||
|
|
||||||
protected Channel channel;
|
|
||||||
|
|
||||||
public AbstractServer(HostAndPort host) {
|
public AbstractServer(HostAndPort host) {
|
||||||
this.hostAddress = host.getHost();
|
this.hostAddress = host.getHost();
|
||||||
this.port = host.getPort();
|
this.port = host.getPort();
|
||||||
@@ -91,7 +89,6 @@ public abstract class AbstractServer<C extends Channel> extends ChannelInitializ
|
|||||||
// 异步
|
// 异步
|
||||||
channelFuture = bootstrap.bind(hostAddress, port);
|
channelFuture = bootstrap.bind(hostAddress, port);
|
||||||
channelFuture.syncUninterruptibly();
|
channelFuture.syncUninterruptibly();
|
||||||
channel = channelFuture.channel();
|
|
||||||
|
|
||||||
allServers.add(this);
|
allServers.add(this);
|
||||||
|
|
||||||
@@ -111,14 +108,6 @@ public abstract class AbstractServer<C extends Channel> extends ChannelInitializ
|
|||||||
logger.warn(e.getMessage(), e);
|
logger.warn(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (channel != null) {
|
|
||||||
try {
|
|
||||||
channel.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.warn(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized static void shutdownAllServers() {
|
public synchronized static void shutdownAllServers() {
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public class TcpServer extends AbstractServer<SocketChannel> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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 IdleStateHandler(0, 0, 180));
|
||||||
channel.pipeline().addLast(new ServerIdleHandler());
|
channel.pipeline().addLast(new ServerIdleHandler());
|
||||||
channel.pipeline().addLast(new TcpCodecHandler());
|
channel.pipeline().addLast(new TcpCodecHandler());
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ public class UdpServer extends AbstractServer<Channel> {
|
|||||||
// 异步
|
// 异步
|
||||||
channelFuture = bootstrap.bind(hostAddress, port);
|
channelFuture = bootstrap.bind(hostAddress, port);
|
||||||
channelFuture.syncUninterruptibly();
|
channelFuture.syncUninterruptibly();
|
||||||
channel = channelFuture.channel();
|
|
||||||
|
|
||||||
allServers.add(this);
|
allServers.add(this);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user