List of usage examples for io.netty.channel ChannelOption RCVBUF_ALLOCATOR
ChannelOption RCVBUF_ALLOCATOR
To view the source code for io.netty.channel ChannelOption RCVBUF_ALLOCATOR.
Click Source Link
From source file:org.vertx.java.core.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); }/* w w w. j av a 2 s. c o m*/ if (tcpReceiveBufferSize != -1) { bootstrap.option(ChannelOption.SO_RCVBUF, tcpReceiveBufferSize); bootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(tcpReceiveBufferSize)); } 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); }
From source file:ratpack.server.internal.DefaultRatpackServer.java
License:Apache License
protected Channel buildChannel(final ServerConfig serverConfig, final ChannelHandler handlerAdapter) throws InterruptedException { SslContext sslContext = serverConfig.getNettySslContext(); this.useSsl = sslContext != null; ServerBootstrap serverBootstrap = new ServerBootstrap(); serverConfig.getConnectTimeoutMillis().ifPresent(i -> { serverBootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, i); serverBootstrap.childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, i); });//from w w w .j a va 2s . c om serverConfig.getMaxMessagesPerRead().ifPresent(i -> { FixedRecvByteBufAllocator allocator = new FixedRecvByteBufAllocator(i); serverBootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, allocator); serverBootstrap.childOption(ChannelOption.RCVBUF_ALLOCATOR, allocator); }); serverConfig.getReceiveBufferSize().ifPresent(i -> { serverBootstrap.option(ChannelOption.SO_RCVBUF, i); serverBootstrap.childOption(ChannelOption.SO_RCVBUF, i); }); serverConfig.getWriteSpinCount().ifPresent(i -> { serverBootstrap.option(ChannelOption.WRITE_SPIN_COUNT, i); serverBootstrap.childOption(ChannelOption.WRITE_SPIN_COUNT, i); }); serverConfig.getConnectQueueSize().ifPresent(i -> serverBootstrap.option(ChannelOption.SO_BACKLOG, i)); return serverBootstrap.group(execController.getEventLoopGroup()) .channel(ChannelImplDetector.getServerSocketChannelImpl()) .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .childHandler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); new ConnectionIdleTimeout(pipeline, serverConfig.getIdleTimeout()); if (sslContext != null) { SSLEngine sslEngine = sslContext.newEngine(PooledByteBufAllocator.DEFAULT); pipeline.addLast("ssl", new SslHandler(sslEngine)); } pipeline.addLast("decoder", new HttpRequestDecoder(serverConfig.getMaxInitialLineLength(), serverConfig.getMaxHeaderSize(), serverConfig.getMaxChunkSize(), false)); pipeline.addLast("encoder", new HttpResponseEncoder()); pipeline.addLast("deflater", new IgnorableHttpContentCompressor()); pipeline.addLast("chunkedWriter", new ChunkedWriteHandler()); pipeline.addLast("adapter", handlerAdapter); ch.config().setAutoRead(false); } }).bind(buildSocketAddress(serverConfig)).sync().channel(); }
From source file:se.sics.gvod.net.NettyNetwork.java
License:Open Source License
/** * Start listening as a server at the given address.. * * @param addr the address to listen at//w w w .j a v a2 s . c o m * @param port the port number to listen at * @param bindAllNetworkIfs whether to bind on all network interfaces * @return true if listening was started * @throws ChannelException in case binding failed */ private boolean bindUdpPort(final InetAddress addr, final int port, final boolean bindAllNetworkIfs) { if (udpPortsToSockets.containsKey(port)) { return true; } EventLoopGroup group = new NioEventLoopGroup(); Bootstrap bootstrap = new Bootstrap(); bootstrap.group(group).channel(NioDatagramChannel.class) .handler(new NettyMsgHandler(component, Transport.UDP, msgDecoderClass)); // Allow packets as large as up to 1600 bytes (default is 768). // You could increase or decrease this value to avoid truncated packets // or to improve memory footprint respectively. // // Please also note that a large UDP packet might be truncated or // dropped by your router no matter how you configured this option. // In UDP, a packet is truncated or dropped if it is larger than a // certain size, depending on router configuration. IPv4 routers // truncate and IPv6 routers drop a large packet. That's why it is // safe to send small packets in UDP. bootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(1500)); bootstrap.option(ChannelOption.SO_RCVBUF, RECV_BUFFER_SIZE); bootstrap.option(ChannelOption.SO_SNDBUF, SEND_BUFFER_SIZE); // bootstrap.setOption("trafficClass", trafficClass); // bootstrap.setOption("soTimeout", soTimeout); // bootstrap.setOption("broadcast", broadcast); bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, CONNECT_TIMEOUT_MS); bootstrap.option(ChannelOption.SO_REUSEADDR, true); try { DatagramChannel c; if (bindAllNetworkIfs) { c = (DatagramChannel) bootstrap.bind( // new InetSocketAddress(port) port).sync().channel(); } else { c = (DatagramChannel) bootstrap.bind(new InetSocketAddress(addr, port)).sync().channel(); } addLocalSocket(new InetSocketAddress(addr, port), c); logger.debug("Successfully bound to ip:port {}:{}", addr, port); } catch (InterruptedException e) { logger.warn("Problem when trying to bind to {}:{}", addr.getHostAddress(), port); trigger(new Fault(e.getCause()), control); return false; } udpSocketsToBootstraps.put(new InetSocketAddress(addr, port), bootstrap); return true; }
From source file:se.sics.kompics.network.netty.NettyNetwork.java
License:Open Source License
private boolean bindUdpPort(final InetAddress addr, final int port) { EventLoopGroup group = new NioEventLoopGroup(); bootstrapUDP = new Bootstrap(); bootstrapUDP.group(group).channel(NioDatagramChannel.class) .handler(new DatagramHandler(this, Transport.UDP)); bootstrapUDP.option(ChannelOption.RCVBUF_ALLOCATOR, new AdaptiveRecvByteBufAllocator(1500, 1500, RECV_BUFFER_SIZE)); bootstrapUDP.option(ChannelOption.SO_RCVBUF, RECV_BUFFER_SIZE); bootstrapUDP.option(ChannelOption.SO_SNDBUF, SEND_BUFFER_SIZE); // bootstrap.setOption("trafficClass", trafficClass); // bootstrap.setOption("soTimeout", soTimeout); // bootstrap.setOption("broadcast", broadcast); bootstrapUDP.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, CONNECT_TIMEOUT_MS); bootstrapUDP.option(ChannelOption.SO_REUSEADDR, true); try {/* ww w .j ava 2 s. c o m*/ InetSocketAddress iAddr = new InetSocketAddress(addr, port); DatagramChannel c = (DatagramChannel) bootstrapUDP.bind(iAddr).sync().channel(); addLocalSocket(iAddr, c); LOG.info("Successfully bound to ip:port {}:{}", addr, port); } catch (InterruptedException e) { LOG.error("Problem when trying to bind to {}:{}", addr.getHostAddress(), port); return false; } return true; }