Refine search
/** * Template method for changing properties on the given {@link SocketChannelConfig}. * <p>The default implementation sets the connect timeout based on the set property. * @param config the channel configuration */ protected void configureChannel(SocketChannelConfig config) { if (this.connectTimeout >= 0) { config.setConnectTimeoutMillis(this.connectTimeout); } }
private static boolean isAllowHalfClosure(ChannelConfig config) { return config instanceof SocketChannelConfig && ((SocketChannelConfig) config).isAllowHalfClosure(); }
@Override protected void initChannel(SocketChannel c) { MessageHandler handler = new MessageHandler(connectionManager); CodecsHandler codecs = new CodecsHandler(ProtocolType.HANDSHAKE.getProtocol()); FramingHandler framing = new FramingHandler(); try { c.config().setOption(ChannelOption.IP_TOS, 0x18); } catch (ChannelException e) { // Not supported on all OSs, like Windows XP and lesser GlowServer.logger.warning("Your OS does not support type of service."); } c.pipeline() .addLast("idle_timeout", new IdleStateHandler(READ_IDLE_TIMEOUT, WRITE_IDLE_TIMEOUT, 0)) .addLast("legacy_ping", new LegacyPingHandler(connectionManager)) .addLast("encryption", NoopHandler.INSTANCE) .addLast("framing", framing) .addLast("compression", NoopHandler.INSTANCE) .addLast("codecs", codecs) .addLast("handler", handler); } }
@Override public void initChannel(SocketChannel ch) { ChannelPipeline p = ch.pipeline(); ch.config().setAllocator(NettyChannelContext.ALLOCATOR); ch.config().setSendBufferSize(NettyChannelContext.BUFFER_SIZE); ch.config().setReceiveBufferSize(NettyChannelContext.BUFFER_SIZE); if (this.pool.getSSLContext() != null) { SSLEngine engine = this.pool.getSSLContext().createSSLEngine(); engine.setUseClientMode(true); p.addLast(SSL_HANDLER, new SslHandler(engine)); } p.addLast(ENCODER_HANDLER, new HttpRequestEncoder()); p.addLast(DECODER_HANDLER, new HttpResponseDecoder( NettyChannelContext.MAX_INITIAL_LINE_LENGTH, NettyChannelContext.MAX_HEADER_SIZE, NettyChannelContext.MAX_CHUNK_SIZE, false)); p.addLast(AGGREGATOR_HANDLER, new HttpObjectAggregator(SocketContext.getMaxRequestSize())); p.addLast(DCP_HANDLER, new NettyHttpServerResponseHandler(this.pool)); } }
@Override public void initChannel(final SocketChannel ch) throws Exception { if(nettyOptions != null) { SocketChannelConfig config = ch.config(); config.setReceiveBufferSize(nettyOptions.rcvbuf()); config.setSendBufferSize(nettyOptions.sndbuf()); config.setKeepAlive(nettyOptions.keepAlive()); config.setReuseAddress(nettyOptions.reuseAddr()); config.setSoLinger(nettyOptions.linger()); config.setTcpNoDelay(nettyOptions.tcpNoDelay()); } if (log.isDebugEnabled()) { log.debug("CONNECT {}", ch); } if (null != getSslOptions()) { SSLEngine ssl = new SSLEngineSupplier(getSslOptions(), false).get(); if (log.isDebugEnabled()) { log.debug("SSL enabled using keystore {}", (null != getSslOptions().keystoreFile() ? getSslOptions().keystoreFile() : "<DEFAULT>")); } ch.pipeline().addLast(new SslHandler(ssl)); } if (null != nettyOptions && null != nettyOptions.pipelineConfigurer()) { nettyOptions.pipelineConfigurer().accept(ch.pipeline()); } bindChannel(handler, ch); } });
@Override public void initChannel( SocketChannel ch ) throws Exception { ch.config().setAllocator( PooledByteBufAllocator.DEFAULT ); if( sslCtx != null ) { ch.pipeline().addLast( sslCtx.newHandler( ch.alloc() ) ); } ch.pipeline().addLast( new SocketTransportHandler( new SocketTransportHandler.ProtocolChooser( protocolVersions ), logging ) ); } } );
@Override public void initChannel( SocketChannel ch ) throws Exception { try { ch.config().setOption( ChannelOption.IP_TOS, 0x18 ); } catch ( ChannelException e ) { // Ignore } ch.config().setAllocator( PooledByteBufAllocator.DEFAULT ); ch.config().setWriteBufferWaterMark( MARK ); Pipeline.prepare( ch.pipeline(), connectionHandler ); } }
@Override protected void initChannel(SocketChannel channel) throws Exception { ChannelPipeline pipeline = channel.pipeline(); if (params != null) { channel.config().setConnectTimeoutMillis( params.getConnectTimeout()); if (options != null) { channel.config().setOptions(options); } pipeline.addLast(new ReadTimeoutHandler(params .getReadTimeout(), TimeUnit.MILLISECONDS)); } pipeline.addLast(new HttpClientCodec()); pipeline.addLast(new HttpContentDecompressor()); pipeline.addLast(new ChunkedWriteHandler()); pipeline.addLast(new HttpResponseDecoder()); pipeline.addLast(new HttpObjectAggregator( Integer.MAX_VALUE)); } });
ChannelPipeline p = ch.pipeline(); ch.config().setAllocator(NettyChannelContext.ALLOCATOR); ch.config().setSendBufferSize(NettyChannelContext.BUFFER_SIZE); ch.config().setReceiveBufferSize(NettyChannelContext.BUFFER_SIZE); ChannelPromise settingsPromise = ch.newPromise(); ch.attr(NettyChannelContext.SETTINGS_PROMISE_KEY).set(settingsPromise);
@Override public void initChannel(final SocketChannel ch) throws Exception { ch.config().setConnectTimeoutMillis(options.timeout()); if(null != sslOpts) { SSLEngine ssl = new SSLEngineSupplier(sslOpts, true).get(); log.debug("SSL enabled using keystore {}", (null != sslOpts.keystoreFile() ? sslOpts.keystoreFile() : "<DEFAULT>")); ch.pipeline().addLast(new SslHandler(ssl)); } if(options instanceof NettyClientSocketOptions && null != ((NettyClientSocketOptions)options) .pipelineConfigurer()) { ((NettyClientSocketOptions)options).pipelineConfigurer().accept(ch.pipeline()); } ch.pipeline().addLast(createChannelHandlers(ch)); ch.closeFuture().addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { connections.remove(ch); } }); } });
@Override public void initChannel(final SocketChannel ch) throws Exception { ch.config().setConnectTimeoutMillis(getOptions().timeout()); if (null != getSslOptions()) { addSecureHandler(ch); } else { ch.config().setAutoRead(false); } if (null != nettyOptions && null != nettyOptions.pipelineConfigurer()) { nettyOptions.pipelineConfigurer().accept(ch.pipeline()); } bindChannel(targetHandler, ch); } });
@Override public void initChannel(final SocketChannel ch) throws Exception { ch.config().setConnectTimeoutMillis(options.timeout()); if (null != sslOptions) { SSLEngine ssl = new SSLEngineSupplier(sslOptions, true).get(); if (log.isDebugEnabled()) { log.debug("SSL enabled using keystore {}", (null != sslOptions.keystoreFile() ? sslOptions.keystoreFile() : "<DEFAULT>")); } ch.pipeline().addLast(new SslHandler(ssl)); } if (null != nettyOptions && null != nettyOptions.pipelineConfigurer()) { nettyOptions.pipelineConfigurer().accept(ch.pipeline()); } ch.pipeline().addLast(createChannelHandlers(ch)); } });
@Override public void connect(SocketAddress endpoint, int timeout) throws IOException { ch.config().setConnectTimeoutMillis(timeout); ch.connect(endpoint).syncUninterruptibly(); }
@Override protected void doWrite(ChannelOutboundBuffer in) throws Exception { SocketChannel ch = javaChannel(); int writeSpinCount = config().getWriteSpinCount(); do { if (in.isEmpty()) {
@Override public void channelCreated(Channel channel) { NioSocketChannel nioSocketChannel = (NioSocketChannel) channel; nioSocketChannel.config().setTcpNoDelay(true).setKeepAlive(true); final ChannelPipeline p = nioSocketChannel.pipeline(); //HTTPS if (sslCtx != null) { p.addLast(sslCtx.newHandler(channel.alloc())); } p.addLast(new HttpClientCodec(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE)); p.addLast(new HttpObjectAggregator(Integer.MAX_VALUE)); } }
@Override protected Executor prepareToClose() { try { if (javaChannel().isOpen() && config().getSoLinger() > 0) { // We need to cancel this key of the channel so we may not end up in a eventloop spin // because we try to read or write until the actual close happens which may be later due // SO_LINGER handling. // See https://github.com/netty/netty/issues/4449 doDeregister(); return GlobalEventExecutor.INSTANCE; } } catch (Throwable ignore) { // Ignore the error as the underlying channel may be closed in the meantime and so // getSoLinger() may produce an exception. In this case we just return null. // See https://github.com/netty/netty/issues/4449 } return null; } }
@Override public void initChannel(NioSocketChannel ch) throws Exception { try { if (!peerDiscoveryMode) { logger.debug("Open {} connection, channel: {}", isInbound() ? "inbound" : "outbound", ch.toString()); } if (notEligibleForIncomingConnection(ch)) { ch.disconnect(); return; } final Channel channel = ctx.getBean(Channel.class); channel.setInetSocketAddress(ch.remoteAddress()); channel.init(ch.pipeline(), remoteId, peerDiscoveryMode, channelManager); if(!peerDiscoveryMode) { channelManager.add(channel); } // limit the size of receiving buffer to 1024 ch.config().setRecvByteBufAllocator(new FixedRecvByteBufAllocator(256 * 1024)); ch.config().setOption(ChannelOption.SO_RCVBUF, 256 * 1024); ch.config().setOption(ChannelOption.SO_BACKLOG, 1024); // be aware of channel closing ch.closeFuture().addListener((ChannelFutureListener) future -> { if (!peerDiscoveryMode) { channelManager.notifyDisconnect(channel); } }); } catch (Exception e) { logger.error("Unexpected error: ", e); } }
public XnioSocketChannel() { super(null); config().setTcpNoDelay(true); }
ChannelPipeline p = ch.pipeline(); ch.config().setAllocator(NettyChannelContext.ALLOCATOR); ch.config().setSendBufferSize(NettyChannelContext.BUFFER_SIZE); ch.config().setReceiveBufferSize(NettyChannelContext.BUFFER_SIZE);