List of usage examples for io.netty.channel ChannelOption SO_SNDBUF
ChannelOption SO_SNDBUF
To view the source code for io.netty.channel ChannelOption SO_SNDBUF.
Click Source Link
From source file:com.baidu.jprotobuf.pbrpc.transport.RpcServer.java
License:Apache License
public RpcServer(Class<? extends ServerChannel> serverChannelClass, RpcServerOptions serverOptions, RpcServiceRegistry rpcServiceRegistry) { if (rpcServiceRegistry == null) { throw new RuntimeException("protperty 'rpcServiceRegistry ' is null."); }/* w ww . j av a2 s .c o m*/ if (serverOptions == null) { serverOptions = new RpcServerOptions(); } this.bossGroup = new NioEventLoopGroup(serverOptions.getAcceptorThreads()); this.workerGroup = new NioEventLoopGroup(serverOptions.getWorkThreads()); this.group(this.bossGroup, this.workerGroup); this.channel(serverChannelClass); this.option(ChannelOption.SO_BACKLOG, serverOptions.getBacklog()); this.childOption(ChannelOption.SO_KEEPALIVE, serverOptions.isKeepAlive()); this.childOption(ChannelOption.SO_REUSEADDR, true); this.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); this.childOption(ChannelOption.TCP_NODELAY, serverOptions.isTcpNoDelay()); this.childOption(ChannelOption.SO_LINGER, serverOptions.getSoLinger()); this.childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, serverOptions.getConnectTimeout()); this.childOption(ChannelOption.SO_RCVBUF, serverOptions.getReceiveBufferSize()); this.childOption(ChannelOption.SO_SNDBUF, serverOptions.getSendBufferSize()); this.rpcServiceRegistry = rpcServiceRegistry; // do register meta service rpcServiceRegistry.doRegisterMetaService(); this.rpcServerOptions = serverOptions; this.rpcServerPipelineInitializer = new RpcServerPipelineInitializer(rpcServiceRegistry, rpcServerOptions); this.childHandler(rpcServerPipelineInitializer); }
From source file:com.barchart.http.server.HttpServer.java
License:BSD License
/** * Start the server with the configuration settings provided. *//* w ww.j a v a 2 s .c o m*/ public ChannelFuture listen() { if (config == null) { throw new IllegalStateException("Server has not been configured"); } if (serverChannel != null) { throw new IllegalStateException("Server is already running."); } final ChannelFuture future = new ServerBootstrap() // .group(config.parentGroup(), config.childGroup()) // .channel(NioServerSocketChannel.class) // .localAddress(config.address()) // .childHandler(new HttpServerChannelInitializer()) // .option(ChannelOption.SO_REUSEADDR, true) // .option(ChannelOption.SO_SNDBUF, 262144) // .option(ChannelOption.SO_RCVBUF, 262144) // .bind(); serverChannel = future.channel(); return future; }
From source file:com.barchart.netty.server.base.AbstractStatefulServer.java
License:BSD License
@Override protected ServerBootstrap bootstrap() { final ServerBootstrap bootstrap = new ServerBootstrap() // .group(defaultGroup, childGroup) // .channel(channelType) // .childHandler(new ServerChannelInitializer()) // .option(ChannelOption.SO_REUSEADDR, true) // .option(ChannelOption.SO_SNDBUF, 262144) // .option(ChannelOption.SO_RCVBUF, 262144) // .childOption(ChannelOption.SO_SNDBUF, 262144) // .childOption(ChannelOption.SO_RCVBUF, 262144); if (bootstrapInit != null) { bootstrapInit.initBootstrap(bootstrap); }//from w w w. ja v a 2s . c o m return bootstrap; }
From source file:com.barchart.netty.server.stream.MulticastTransceiver.java
License:BSD License
@Override protected Bootstrap bootstrap() { final Bootstrap bootstrap = new Bootstrap() // .group(defaultGroup) // .channel(NioDatagramChannel.class) // .handler(new ServerChannelInitializer()) // .option(ChannelOption.SO_REUSEADDR, true) // .option(ChannelOption.IP_MULTICAST_TTL, 3) // .option(ChannelOption.SO_SNDBUF, 262144) // .option(ChannelOption.SO_RCVBUF, 262144); if (bootstrapInit != null) { bootstrapInit.initBootstrap(bootstrap); }//from w w w . j ava 2 s .c om return bootstrap; }
From source file:com.barchart.netty.server.stream.UnicastTransceiver.java
License:BSD License
@Override protected Bootstrap bootstrap() { final Bootstrap bootstrap = new Bootstrap() // .group(defaultGroup) // .channel(NioDatagramChannel.class) // .handler(new ServerChannelInitializer()) // .remoteAddress(remote) // .option(ChannelOption.SO_REUSEADDR, true) // .option(ChannelOption.IP_MULTICAST_TTL, 3) // .option(ChannelOption.SO_SNDBUF, 262144) // .option(ChannelOption.SO_RCVBUF, 262144); if (bootstrapInit != null) { bootstrapInit.initBootstrap(bootstrap); }/*from w w w. j ava 2s . c o m*/ return bootstrap; }
From source file:com.caocao.nio.server.NettyServer.java
License:Apache License
public void initAndStart() { System.out.println("port:" + port); // Configure the server. bossGroup = new NioEventLoopGroup(Runtime.getRuntime().availableProcessors() * 2); workerGroup = new NioEventLoopGroup(Runtime.getRuntime().availableProcessors() * 2); try {// w w w . j a va 2 s .c om ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 128).option(ChannelOption.SO_KEEPALIVE, true) .option(ChannelOption.TCP_NODELAY, true).option(ChannelOption.SO_SNDBUF, 5 * 1024) .option(ChannelOption.SO_SNDBUF, 5 * 1024) .option(ChannelOption.RCVBUF_ALLOCATOR, new AdaptiveRecvByteBufAllocator(40, 64, 1024)) .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new CustomerInitializer()); // Start the server. ChannelFuture f = b.bind(port).sync(); // Wait until the server socket is closed. f.channel().closeFuture().sync(); } catch (InterruptedException e) { logger.error("netty??", e); } finally { // Shut down all event loops to terminate all threads. bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.comphenix.protocol.compat.netty.independent.NettySocketAdapter.java
License:Open Source License
@Override public synchronized int getSendBufferSize() throws SocketException { return ch.config().getOption(ChannelOption.SO_SNDBUF); }
From source file:com.comphenix.protocol.compat.netty.independent.NettySocketAdapter.java
License:Open Source License
@Override public synchronized void setSendBufferSize(int size) throws SocketException { ch.config().setOption(ChannelOption.SO_SNDBUF, size); }
From source file:com.corundumstudio.socketio.SocketIOServer.java
License:Apache License
protected void applyConnectionOptions(ServerBootstrap bootstrap) { SocketConfig config = configCopy.getSocketConfig(); bootstrap.childOption(ChannelOption.TCP_NODELAY, config.isTcpNoDelay()); if (config.getTcpSendBufferSize() != -1) { bootstrap.childOption(ChannelOption.SO_SNDBUF, config.getTcpSendBufferSize()); }/* w w w.j av a 2 s . co m*/ if (config.getTcpReceiveBufferSize() != -1) { bootstrap.childOption(ChannelOption.SO_RCVBUF, config.getTcpReceiveBufferSize()); bootstrap.childOption(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(config.getTcpReceiveBufferSize())); } bootstrap.childOption(ChannelOption.SO_KEEPALIVE, config.isTcpKeepAlive()); bootstrap.option(ChannelOption.SO_LINGER, config.getSoLinger()); bootstrap.option(ChannelOption.SO_REUSEADDR, config.isReuseAddress()); bootstrap.option(ChannelOption.SO_BACKLOG, config.getAcceptBackLog()); }
From source file:com.dinstone.jrpc.transport.netty4.NettyAcceptance.java
License:Apache License
@Override public Acceptance bind() { bossGroup = new NioEventLoopGroup(1, new DefaultThreadFactory("N4A-Boss")); workGroup = new NioEventLoopGroup(transportConfig.getNioProcessorCount(), new DefaultThreadFactory("N4A-Work")); ServerBootstrap boot = new ServerBootstrap().group(bossGroup, workGroup); boot.channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() { @Override/* w ww.ja v a 2 s . c om*/ public void initChannel(SocketChannel ch) throws Exception { TransportProtocolDecoder decoder = new TransportProtocolDecoder(); decoder.setMaxObjectSize(transportConfig.getMaxSize()); TransportProtocolEncoder encoder = new TransportProtocolEncoder(); encoder.setMaxObjectSize(transportConfig.getMaxSize()); ch.pipeline().addLast("TransportProtocolDecoder", decoder); ch.pipeline().addLast("TransportProtocolEncoder", encoder); int intervalSeconds = transportConfig.getHeartbeatIntervalSeconds(); ch.pipeline().addLast("IdleStateHandler", new IdleStateHandler(intervalSeconds * 2, 0, 0)); ch.pipeline().addLast("NettyServerHandler", new NettyServerHandler()); } }); boot.option(ChannelOption.SO_REUSEADDR, true).option(ChannelOption.SO_BACKLOG, 128); boot.childOption(ChannelOption.SO_RCVBUF, 16 * 1024).childOption(ChannelOption.SO_SNDBUF, 16 * 1024) .childOption(ChannelOption.TCP_NODELAY, true); try { boot.bind(serviceAddress).sync(); int processorCount = transportConfig.getBusinessProcessorCount(); if (processorCount > 0) { NamedThreadFactory threadFactory = new NamedThreadFactory("N4A-BusinessProcessor"); executorService = Executors.newFixedThreadPool(processorCount, threadFactory); } } catch (Exception e) { throw new RuntimeException("can't bind service on " + serviceAddress, e); } LOG.info("netty acceptance bind on {}", serviceAddress); return this; }