SocketException:无效的参数

时间:2015-12-14 16:00:22

标签: netty

我根据netty 4.0.32.Final写了传输服务器

在极少数情况下,我在Oracle Solaris 11.1 SPARC上遇到下一个错误:

Failed to set a channel option: [id: 0x970c09c4, /91.221.145.225:48986 => /0.0.0.0:0]
io.netty.channel.ChannelException: java.net.SocketException: Invalid argument
at io.netty.channel.socket.DefaultSocketChannelConfig.setReuseAddress(DefaultSocketChannelConfig.java:222)
at io.netty.channel.socket.DefaultSocketChannelConfig.setOption(DefaultSocketChannelConfig.java:113)
at io.netty.bootstrap.ServerBootstrap$ServerBootstrapAcceptor.channelRead(ServerBootstrap.java:239)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846)
at io.netty.channel.nio.AbstractNioMessageChannel$NioMessageUnsafe.read(AbstractNioMessageChannel.java:93)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.SocketException: Invalid argument
at sun.nio.ch.Net.setIntOption0(Native Method)
at sun.nio.ch.Net.setSocketOption(Net.java:356)
at sun.nio.ch.SocketChannelImpl.setOption(SocketChannelImpl.java:190)
at sun.nio.ch.SocketAdaptor.setBooleanOption(SocketAdaptor.java:271)
at sun.nio.ch.SocketAdaptor.setReuseAddress(SocketAdaptor.java:389)
at io.netty.channel.socket.DefaultSocketChannelConfig.setReuseAddress(DefaultSocketChannelConfig.java:220)
... 12 more

以下是选项[SO_REUSEADDR = true,TCP_NODELAY = true,SO_LINGER = -1,WRITE_BUFFER_LOW_WATER_MARK = 10240,WRITE_BUFFER_HIGH_WATER_MARK = 20480,MESSAGE_SIZE_ESTIMATOR =io.netty.channel.DefaultMessageSizeEstimator@350c136d]

我已经调查过,sun.nio.ch.Net.setIntOption0(Native Method)的本机调用毕竟会导致setsockopt调用。

在此处列出的文档中http://docs.oracle.com/cd/E26505_01/html/816-5170/getsockopt-3socket.html 写得:

EINVAL 指定的选项在指定的套接字级别无效,或者套接字已关闭。

因此,可能会出现“无效参数”错误,因为在我的应用程序尝试设置套接字选项时套接字已关闭...

我的调查是否正确? 如果是的话,是否有可能以某种方式检测网络代码中的这种情况以防止此类错误而不调用选项集?

0 个答案:

没有答案