List of usage examples for io.netty.channel ChannelOption SO_LINGER
ChannelOption SO_LINGER
To view the source code for io.netty.channel ChannelOption SO_LINGER.
Click Source Link
From source file:com.vmware.xenon.common.http.netty.NettyHttpListener.java
License:Open Source License
@Override public void start(int port, String bindAddress) throws Throwable { this.nettyExecutorService = Executors.newFixedThreadPool(EVENT_LOOP_THREAD_COUNT, r -> new Thread(r, this.host.getUri().toString() + "/netty-listener/" + this.host.getId())); this.eventLoopGroup = new NioEventLoopGroup(EVENT_LOOP_THREAD_COUNT, this.nettyExecutorService); if (this.childChannelHandler == null) { this.childChannelHandler = new NettyHttpServerInitializer(this.host, this.sslContext, this.responsePayloadSizeLimit); }/*from w ww .j a va 2 s. c om*/ ServerBootstrap b = new ServerBootstrap(); b.group(this.eventLoopGroup).channel(NioServerSocketChannel.class).childHandler(this.childChannelHandler); InetSocketAddress addr; if (bindAddress != null) { addr = new InetSocketAddress(bindAddress, port); } else { this.host.log(Level.WARNING, "*** Binding to all interfaces, please supply a bindAddress instead ***"); addr = new InetSocketAddress(port); } this.serverChannel = b.bind(addr).sync().channel(); this.serverChannel.config().setOption(ChannelOption.SO_LINGER, 0); this.port = ((InetSocketAddress) this.serverChannel.localAddress()).getPort(); this.isListening = true; }
From source file:io.advantageous.conekt.http.impl.HttpClientImpl.java
License:Open Source License
private void applyConnectionOptions(Bootstrap bootstrap) { bootstrap.option(ChannelOption.TCP_NODELAY, options.isTcpNoDelay()); if (options.getSendBufferSize() != -1) { bootstrap.option(ChannelOption.SO_SNDBUF, options.getSendBufferSize()); }/*from w ww. j ava2 s. com*/ if (options.getReceiveBufferSize() != -1) { bootstrap.option(ChannelOption.SO_RCVBUF, options.getReceiveBufferSize()); bootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(options.getReceiveBufferSize())); } if (options.getSoLinger() != -1) { bootstrap.option(ChannelOption.SO_LINGER, options.getSoLinger()); } if (options.getTrafficClass() != -1) { bootstrap.option(ChannelOption.IP_TOS, options.getTrafficClass()); } bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, options.getConnectTimeout()); bootstrap.option(ChannelOption.ALLOCATOR, PartialPooledByteBufAllocator.INSTANCE); bootstrap.option(ChannelOption.SO_KEEPALIVE, options.isTcpKeepAlive()); bootstrap.option(ChannelOption.SO_REUSEADDR, options.isReuseAddress()); }
From source file:io.advantageous.conekt.http.impl.HttpServerImpl.java
License:Open Source License
private void applyConnectionOptions(ServerBootstrap bootstrap) { bootstrap.childOption(ChannelOption.TCP_NODELAY, options.isTcpNoDelay()); if (options.getSendBufferSize() != -1) { bootstrap.childOption(ChannelOption.SO_SNDBUF, options.getSendBufferSize()); }//from ww w .jav a 2 s .c om if (options.getReceiveBufferSize() != -1) { bootstrap.childOption(ChannelOption.SO_RCVBUF, options.getReceiveBufferSize()); bootstrap.childOption(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(options.getReceiveBufferSize())); } if (options.getSoLinger() != -1) { bootstrap.option(ChannelOption.SO_LINGER, options.getSoLinger()); } if (options.getTrafficClass() != -1) { bootstrap.childOption(ChannelOption.IP_TOS, options.getTrafficClass()); } bootstrap.childOption(ChannelOption.ALLOCATOR, PartialPooledByteBufAllocator.INSTANCE); bootstrap.childOption(ChannelOption.SO_KEEPALIVE, options.isTcpKeepAlive()); bootstrap.option(ChannelOption.SO_REUSEADDR, options.isReuseAddress()); if (options.getAcceptBacklog() != -1) { bootstrap.option(ChannelOption.SO_BACKLOG, options.getAcceptBacklog()); } }
From source file:io.advantageous.conekt.net.impl.NetClientImpl.java
License:Open Source License
private void applyConnectionOptions(Bootstrap bootstrap) { bootstrap.option(ChannelOption.TCP_NODELAY, options.isTcpNoDelay()); if (options.getSendBufferSize() != -1) { bootstrap.option(ChannelOption.SO_SNDBUF, options.getSendBufferSize()); }//w w w .j a va 2s . co m if (options.getReceiveBufferSize() != -1) { bootstrap.option(ChannelOption.SO_RCVBUF, options.getReceiveBufferSize()); bootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(options.getReceiveBufferSize())); } if (options.getSoLinger() != -1) { bootstrap.option(ChannelOption.SO_LINGER, options.getSoLinger()); } if (options.getTrafficClass() != -1) { bootstrap.option(ChannelOption.IP_TOS, options.getTrafficClass()); } bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, options.getConnectTimeout()); bootstrap.option(ChannelOption.ALLOCATOR, PartialPooledByteBufAllocator.INSTANCE); bootstrap.option(ChannelOption.SO_KEEPALIVE, options.isTcpKeepAlive()); }
From source file:io.advantageous.conekt.net.impl.NetServerImpl.java
License:Open Source License
private void applyConnectionOptions(ServerBootstrap bootstrap) { bootstrap.childOption(ChannelOption.TCP_NODELAY, options.isTcpNoDelay()); if (options.getSendBufferSize() != -1) { bootstrap.childOption(ChannelOption.SO_SNDBUF, options.getSendBufferSize()); }//from w w w . ja va2s .c om if (options.getReceiveBufferSize() != -1) { bootstrap.childOption(ChannelOption.SO_RCVBUF, options.getReceiveBufferSize()); bootstrap.childOption(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(options.getReceiveBufferSize())); } if (options.getSoLinger() != -1) { bootstrap.option(ChannelOption.SO_LINGER, options.getSoLinger()); } if (options.getTrafficClass() != -1) { bootstrap.childOption(ChannelOption.IP_TOS, options.getTrafficClass()); } bootstrap.childOption(ChannelOption.ALLOCATOR, PartialPooledByteBufAllocator.INSTANCE); bootstrap.childOption(ChannelOption.SO_KEEPALIVE, options.isTcpKeepAlive()); bootstrap.option(ChannelOption.SO_REUSEADDR, options.isReuseAddress()); if (options.getAcceptBacklog() != -1) { bootstrap.option(ChannelOption.SO_BACKLOG, options.getAcceptBacklog()); } }
From source file:io.grpc.netty.NettyClientTransportTest.java
License:Apache License
@Test public void setSoLingerChannelOption() throws IOException { startServer();//from w w w .ja va 2s. c om Map<ChannelOption<?>, Object> channelOptions = new HashMap<>(); // set SO_LINGER option int soLinger = 123; channelOptions.put(ChannelOption.SO_LINGER, soLinger); NettyClientTransport transport = new NettyClientTransport(address, new ReflectiveChannelFactory<>(NioSocketChannel.class), channelOptions, group, newNegotiator(), DEFAULT_WINDOW_SIZE, DEFAULT_MAX_MESSAGE_SIZE, GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE, KEEPALIVE_TIME_NANOS_DISABLED, 1L, false, authority, null /* user agent */, tooManyPingsRunnable, new TransportTracer(), Attributes.EMPTY, new SocketPicker(), new FakeChannelLogger()); transports.add(transport); callMeMaybe(transport.start(clientTransportListener)); // verify SO_LINGER has been set ChannelConfig config = transport.channel().config(); assertTrue(config instanceof SocketChannelConfig); assertEquals(soLinger, ((SocketChannelConfig) config).getSoLinger()); }
From source file:io.grpc.netty.UtilsTest.java
License:Apache License
@Test public void channelOptionsTest_noLinger() { Channel channel = new EmbeddedChannel(); assertNull(channel.config().getOption(ChannelOption.SO_LINGER)); InternalChannelz.SocketOptions socketOptions = Utils.getSocketOptions(channel); assertNull(socketOptions.lingerSeconds); }
From source file:io.grpc.netty.UtilsTest.java
License:Apache License
private static InternalChannelz.SocketOptions setAndValidateGeneric(Channel channel) { channel.config().setOption(ChannelOption.SO_LINGER, 3); // only applicable for OIO channels: channel.config().setOption(ChannelOption.SO_TIMEOUT, 250); // Test some arbitrarily chosen options with a non numeric values channel.config().setOption(ChannelOption.SO_KEEPALIVE, true); WriteBufferWaterMark writeBufWaterMark = new WriteBufferWaterMark(10, 20); channel.config().setOption(ChannelOption.WRITE_BUFFER_WATER_MARK, writeBufWaterMark); InternalChannelz.SocketOptions socketOptions = Utils.getSocketOptions(channel); assertEquals(3, (int) socketOptions.lingerSeconds); assertEquals("true", socketOptions.others.get("SO_KEEPALIVE")); assertEquals(writeBufWaterMark.toString(), socketOptions.others.get(ChannelOption.WRITE_BUFFER_WATER_MARK.toString())); return socketOptions; }
From source file:io.jsync.net.impl.TCPSSLHelper.java
License:Open Source License
public void applyConnectionOptions(ServerBootstrap bootstrap) { bootstrap.childOption(ChannelOption.TCP_NODELAY, tcpNoDelay); if (tcpSendBufferSize != -1) { bootstrap.childOption(ChannelOption.SO_SNDBUF, tcpSendBufferSize); }//from w w w . j a v a 2s.com if (tcpReceiveBufferSize != -1) { bootstrap.childOption(ChannelOption.SO_RCVBUF, tcpReceiveBufferSize); bootstrap.childOption(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(tcpReceiveBufferSize)); } // TODO this may not be needed if (soLinger != -1) { bootstrap.option(ChannelOption.SO_LINGER, soLinger); } if (trafficClass != -1) { bootstrap.childOption(ChannelOption.IP_TOS, trafficClass); } bootstrap.childOption(ChannelOption.ALLOCATOR, PartialPooledByteBufAllocator.INSTANCE); bootstrap.childOption(ChannelOption.SO_KEEPALIVE, tcpKeepAlive); bootstrap.option(ChannelOption.SO_REUSEADDR, reuseAddress); bootstrap.option(ChannelOption.SO_BACKLOG, acceptBackLog); }
From source file:io.jsync.net.impl.TCPSSLHelper.java
License:Open Source License
public void applyConnectionOptions(Bootstrap bootstrap) { bootstrap.option(ChannelOption.TCP_NODELAY, tcpNoDelay); if (tcpSendBufferSize != -1) { bootstrap.option(ChannelOption.SO_SNDBUF, tcpSendBufferSize); }//www.ja va 2s . c om if (tcpReceiveBufferSize != -1) { bootstrap.option(ChannelOption.SO_RCVBUF, tcpReceiveBufferSize); bootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(tcpReceiveBufferSize)); } if (soLinger != -1) { bootstrap.option(ChannelOption.SO_LINGER, soLinger); } if (trafficClass != -1) { bootstrap.option(ChannelOption.IP_TOS, trafficClass); } bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectTimeout); bootstrap.option(ChannelOption.ALLOCATOR, PartialPooledByteBufAllocator.INSTANCE); bootstrap.option(ChannelOption.SO_KEEPALIVE, tcpKeepAlive); }