我使用的是Netty版本2.6.0.Final.
如果我正确理解Netty文档,在Channel上调用disconnect()应该允许我稍后再调用connect()来连接.但是,当我调用disconnect()时,我的SimpleChannelHandler子类的channelDisconnected()和channelClosed()都被调用.
我在调试模式下打开它,基本上事件的顺序是:
调用Channels.disconnect():
public static ChannelFuture disconnect(Channel channel) {
ChannelFuture future = future(channel);
channel.getPipeline().sendDownstream(new DownstreamChannelStateEvent(
channel, future, ChannelState.CONNECTED, null));
return future;
}
Run Code Online (Sandbox Code Playgroud)最终,NioSocketPipelineSink.eventSunk()被调用,相关部分是:
case CONNECTED:
if (value != null) {
connect(channel, future, (SocketAddress) value);
} else {
channel.worker.close(channel, future);
}
break;
Run Code Online (Sandbox Code Playgroud)因此,由于value为null且状态为CONNECTED,因此通道将关闭(尽管根据此处 CONNECTED with null应指示断开连接的请求,不一定关闭.
我在这里错过了一些东西吗?如果它只是导致通道被关闭,那么disconnect()的重点是什么?
这不是一个大问题,因为如果我需要,我可以为我的情况创建一个新的频道,但从最初的检查看起来这似乎是一个Netty错误,除非我只是误解了它应该如何工作或我'做一些傻事.
netty ×1