本文介绍了Netty的非阻塞通道中的SO_TIMEOUT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果某个通道未在超时毫秒内接收到读取/响应,那么SO_TIMEOUT是否会终止非阻塞通道?
Does the SO_TIMEOUT expire the Non blocking channel , if a channel doesn't receive a read/response in timeout millis?
bootstrap.group(workerGroup).channel(NioSocketChannel.class).
.handler(channelInitializer).option(ChannelOption.SO_TIMEOUT, 100);
该选项也适用于服务器通道吗?像:
Also, is the option applicable for server channel also? like:
serverBootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).
localAddress(new InetSocketAddress(8800)).childHandler(serverChannelInitializer).
option(ChannelOption.SO_TIMEOUT, 100).bind().sync();
推荐答案
否. SO_TIMEOUT
仅对OIO套接字传输有效.您应该在userEventTriggered()
实现中使用IdleStateHandler
并处理IdleStateEvent
.
No. SO_TIMEOUT
has effect only for OIO socket transport. You should use IdleStateHandler
and handle an IdleStateEvent
in your userEventTriggered()
implementation.
这篇关于Netty的非阻塞通道中的SO_TIMEOUT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!