Netty - 忽略IP_TOS的失败设置

时间:2013-02-09 22:11:41

标签: java netty

我的用户向我报告此错误,我想默默忽略它,因为它是我应用程序中不重要的部分。

  

2013-02-09 15:20:15 [警告]无法设置频道选项:[id:0x8cf59443,/ 84.100.204.150:51292 => /87.98.181.225:22091]   io.netty.channel.ChannelException:java.net.SocketException:无效参数:无更多信息       at io.netty.channel.socket.DefaultSocketChannelConfig.setTrafficClass(DefaultSocketChannelConfig.java:264)       at io.netty.channel.socket.DefaultSocketChannelConfig.setOption(DefaultSocketChannelConfig.java:115)       at io.netty.bootstrap.ServerBootstrap $ ServerBootstrapAcceptor.inboundBufferUpdated(ServerBootstrap.java:264)       at io.netty.channel.DefaultChannelHandlerContext.invokeInboundBufferUpdated(DefaultChannelHandlerContext.java:1170)       at io.netty.channel.DefaultChannelHandlerContext.fireInboundBufferUpdated0(DefaultChannelHandlerContext.java:1148)       at io.netty.channel.DefaultChannelHandlerContext.fireInboundBufferUpdated(DefaultChannelHandlerContext.java:1127)       在io.netty.channel.DefaultChannelPipeline.fireInboundBufferUpdated(DefaultChannelPipeline.java:903)       at io.netty.channel.socket.nio.AbstractNioMessageChannel $ NioMessageUnsafe.read(AbstractNioMessageChannel.java:84)       at io.netty.channel.socket.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:397)       at io.netty.channel.socket.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:361)       在io.netty.channel.socket.nio.NioEventLoop.run(NioEventLoop.java:301)       at io.netty.channel.SingleThreadEventExecutor $ 2.run(SingleThreadEventExecutor.java:110)       在java.lang.Thread.run(未知来源)   引起:java.net.SocketException:无效参数:无更多信息       at sun.nio.ch.Net.setIntOption0(原生方法)       at sun.nio.ch.Net.setSocketOption(Unknown Source)       at sun.nio.ch.SocketChannelImpl.setOption(Unknown Source)       at sun.nio.ch.SocketAdaptor.setIntOption(Unknown Source)       at sun.nio.ch.SocketAdaptor.setTrafficClass(Unknown Source)       at io.netty.channel.socket.DefaultSocketChannelConfig.setTrafficClass(DefaultSocketChannelConfig.java:262)       ......还有12个

要完成此操作,我只需在IP_TOS中设置ServerBootstrap选项即可: childOption(ChannelOption.IP_TOS, 0x18)

如果您知道我需要放置处理程序的位置,或选择忽略设置此选项时的失败,请告知我们。

md_5

1 个答案:

答案 0 :(得分:3)

这是一个设置选项的示例引导代码:

        Bootstrap b = new Bootstrap();
        b.group(new NioEventLoopGroup(), new NioEventLoopGroup())
         .channel(NioServerSocketChannel.class)
         .option(ChannelOption.SO_BACKLOG, 100)
         .handler(new LoggingHandler(LogLevel.INFO))
         .childHandler(new ChannelInitializer<SocketChannel>() {
             @Override
             public void initChannel(SocketChannel ch) throws Exception {
                 try {
                     ch.config().setTrafficClass(0x18);
                 } catch (ChannelException e) {
                     // Ignore
                 }
                 ch.pipeline().addLast(
                         new LoggingHandler(LogLevel.INFO),
                         new EchoServerHandler());
             }
         });