@Override protected void initChannel(SocketChannel ch) throws Exception { try { ch.config().setOption(ChannelOption.IP_TOS, 0x18); // ch.config().setOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 32 * 1024); // ch.config().setOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 8 * 1024); } catch (ChannelException ex) { // IP_TOS not supported by platform, ignore } ch.config().setAllocator(PooledByteBufAllocator.DEFAULT); PacketRegistry r = new PacketRegistry(); ch.pipeline().addLast(new HttpServerCodec()); ch.pipeline().addLast(new HttpObjectAggregator(65536)); ch.pipeline().addLast(new WebSocketHandler()); ch.pipeline().addLast(new PacketDecoder(r)); ch.pipeline().addLast(new PacketEncoder(r)); ch.pipeline().addLast(new ClientHandler(server)); }
@Override protected void initChannel(SocketChannel ch) throws Exception { try { ch.config().setOption(ChannelOption.TCP_NODELAY, true); ch.config().setOption(ChannelOption.IP_TOS, 0x18); } catch (ChannelException ex) { // IP_TOS not supported by platform, ignore } ch.config().setAllocator(PooledByteBufAllocator.DEFAULT); PacketRegistry r = new PacketRegistry(); ch.pipeline().addLast("idleStateHandler", new IdleStateHandler(0, 0, 30)); ch.pipeline().addLast(new HttpServerCodec()); ch.pipeline().addLast(new HttpObjectAggregator(65536)); ch.pipeline().addLast(new WebSocketHandler()); ch.pipeline().addLast(new PacketDecoder(r)); ch.pipeline().addLast(new PacketEncoder(r)); ch.pipeline().addLast(mExecutorGroup, "serverHandler", new ClientHandler(mServer)); }
@Override protected void initChannel(SocketChannel ch) throws Exception { try { ch.config().setOption(ChannelOption.IP_TOS, 0x18); } catch (ChannelException ex) { // IP_TOS not supported by platform, ignore } ch.config().setAllocator(PooledByteBufAllocator.DEFAULT); ch.pipeline().addLast(new HttpServerCodec()); ch.pipeline().addLast(new HttpObjectAggregator(65536)); ch.pipeline().addLast(new WebSocketHandler()); ch.pipeline().addLast(new PacketDecoder()); ch.pipeline().addLast(new PacketEncoder()); ch.pipeline().addLast(new ClientHandler(server)); }
@Override protected void initChannel(SocketChannel ch) throws Exception { try { ch.config().setOption(ChannelOption.IP_TOS, 0x18); } catch (ChannelException ex) { // IP_TOS not supported by platform, ignore } ch.config().setAllocator(PooledByteBufAllocator.DEFAULT); ch.pipeline().addLast(new HttpServerCodec()); ch.pipeline().addLast(new HttpObjectAggregator(65536)); ch.pipeline().addLast(new Handshaker()); ch.pipeline().addLast(new WebSocketHandler()); ch.pipeline().addLast(new PacketDecoder()); ch.pipeline().addLast(new PacketEncoder()); ch.pipeline().addLast(new ClientHandler(server)); }
@Override public void initChannel(Channel ch) throws Exception { try { ch.config().setOption( ChannelOption.IP_TOS, 0x18 ); } catch ( ChannelException ex ) { // IP_TOS is not supported (Windows XP / Windows Server 2003) } ch.config().setOption( ChannelOption.TCP_NODELAY, true ); ch.config().setAllocator( PooledByteBufAllocator.DEFAULT ); ch.pipeline().addLast( TIMEOUT_HANDLER, new ReadTimeoutHandler( BungeeCord.getInstance().config.getTimeout(), TimeUnit.MILLISECONDS ) ); ch.pipeline().addLast( FRAME_DECODER, new Varint21FrameDecoder() ); ch.pipeline().addLast( FRAME_PREPENDER, framePrepender ); ch.pipeline().addLast( BOSS_HANDLER, new HandlerBoss() ); }
/** * Start proxy server * */ public void start() throws InterruptedException { ServerBootstrap serverBootstrap = new ServerBootstrap(); serverBootstrap.group(_acceptorGroup, _upstreamWorkerGroup); serverBootstrap.channelFactory(new ChannelFactory<ServerChannel>() { @Override public ServerChannel newChannel() { return new NioServerSocketChannel(); } }); serverBootstrap.childHandler(new ProxyInitializer(this)); //bind ChannelFuture future = serverBootstrap.bind(_host, _port); //wait for the future future.awaitUninterruptibly(); if (!future.isSuccess()) { future.channel().closeFuture().awaitUninterruptibly(); throw new ChannelException(String.format("Failed to bind to: %s:%d", _host, _port), future.cause()); } else { _allChannels.add(future.channel()); } }
protected NioUdtAcceptorChannel(final ServerSocketChannelUDT channelUDT) { super(null, channelUDT, OP_ACCEPT); try { channelUDT.configureBlocking(false); config = new DefaultUdtServerChannelConfig(this, channelUDT, true); } catch (final Exception e) { try { channelUDT.close(); } catch (final Exception e2) { if (logger.isWarnEnabled()) { logger.warn("Failed to close channel.", e2); } } throw new ChannelException("Failed to configure channel.", e); } }
@Override public DatagramChannelConfig setBroadcast(boolean broadcast) { try { // See: https://github.com/netty/netty/issues/576 if (broadcast && !javaSocket.getLocalAddress().isAnyLocalAddress() && !PlatformDependent.isWindows() && !PlatformDependent.isRoot()) { // Warn a user about the fact that a non-root user can't receive a // broadcast packet on *nix if the socket is bound on non-wildcard address. logger.warn( "A non-root user can't receive a broadcast packet if the socket " + "is not bound to a wildcard address; setting the SO_BROADCAST flag " + "anyway as requested on the socket which is bound to " + javaSocket.getLocalSocketAddress() + '.'); } javaSocket.setBroadcast(broadcast); } catch (SocketException e) { throw new ChannelException(e); } return this; }
static LocalAddress register( Channel channel, LocalAddress oldLocalAddress, SocketAddress localAddress) { if (oldLocalAddress != null) { throw new ChannelException("already bound"); } if (!(localAddress instanceof LocalAddress)) { throw new ChannelException("unsupported address type: " + StringUtil.simpleClassName(localAddress)); } LocalAddress addr = (LocalAddress) localAddress; if (LocalAddress.ANY.equals(addr)) { addr = new LocalAddress(channel); } Channel boundChannel = boundChannels.putIfAbsent(addr, channel); if (boundChannel != null) { throw new ChannelException("address already in use by: " + boundChannel); } return addr; }
/** * Create a new instance * * @param parent the parent {@link Channel} by which this instance was created. May be {@code null} * @param ch the underlying {@link SelectableChannel} on which it operates * @param readInterestOp the ops to set to receive data from the {@link SelectableChannel} */ protected AbstractNioChannel(Channel parent, SelectableChannel ch, int readInterestOp) { super(parent); this.ch = ch; this.readInterestOp = readInterestOp; try { ch.configureBlocking(false); } catch (IOException e) { try { ch.close(); } catch (IOException e2) { if (logger.isWarnEnabled()) { logger.warn( "Failed to close a partially initialized socket.", e2); } } throw new ChannelException("Failed to enter non-blocking mode.", e); } }
/** * Create a new instance * * @param parent the {@link Channel} which is the parent of this {@link NioSctpChannel} * or {@code null}. * @param sctpChannel the underlying {@link SctpChannel} */ public NioSctpChannel(Channel parent, SctpChannel sctpChannel) { super(parent, sctpChannel, SelectionKey.OP_READ); try { sctpChannel.configureBlocking(false); config = new NioSctpChannelConfig(this, sctpChannel); notificationHandler = new SctpNotificationHandler(this); } catch (IOException e) { try { sctpChannel.close(); } catch (IOException e2) { if (logger.isWarnEnabled()) { logger.warn( "Failed to close a partially initialized sctp channel.", e2); } } throw new ChannelException("Failed to enter non-blocking mode.", e); } }
protected NioUdtAcceptorChannel(EventLoop eventLoop, EventLoopGroup childGroup, ServerSocketChannelUDT channelUDT) { super(null, eventLoop, childGroup, channelUDT, OP_ACCEPT); try { channelUDT.configureBlocking(false); config = new DefaultUdtServerChannelConfig(this, channelUDT, true); } catch (final Exception e) { try { channelUDT.close(); } catch (final Exception e2) { if (logger.isWarnEnabled()) { logger.warn("Failed to close channel.", e2); } } throw new ChannelException("Failed to configure channel.", e); } }
/** * Create a new instance from the given {@link MulticastSocket}. * * @param socket the {@link MulticastSocket} which is used by this instance */ public OioDatagramChannel(EventLoop eventLoop, MulticastSocket socket) { super(null, eventLoop); boolean success = false; try { socket.setSoTimeout(SO_TIMEOUT); socket.setBroadcast(false); success = true; } catch (SocketException e) { throw new ChannelException( "Failed to configure the datagram socket timeout.", e); } finally { if (!success) { socket.close(); } } this.socket = socket; config = new DefaultDatagramChannelConfig(this, socket); }
/** * Create a new instance * * @param parent the {@link Channel} which is the parent of this {@link NioSctpChannel} * or {@code null}. * @param sctpChannel the underlying {@link SctpChannel} */ public NioSctpChannel(Channel parent, EventLoop eventLoop, SctpChannel sctpChannel) { super(parent, eventLoop, sctpChannel, SelectionKey.OP_READ); try { sctpChannel.configureBlocking(false); config = new DefaultSctpChannelConfig(this, sctpChannel); notificationHandler = new SctpNotificationHandler(this); } catch (IOException e) { try { sctpChannel.close(); } catch (IOException e2) { if (logger.isWarnEnabled()) { logger.warn( "Failed to close a partially initialized sctp channel.", e2); } } throw new ChannelException("Failed to enter non-blocking mode.", e); } }
public static NetworkManager func_181124_a(InetAddress p_181124_0_, int p_181124_1_, boolean p_181124_2_) { final NetworkManager networkmanager = new NetworkManager(EnumPacketDirection.CLIENTBOUND); Class <? extends SocketChannel > oclass; LazyLoadBase <? extends EventLoopGroup > lazyloadbase; if (Epoll.isAvailable() && p_181124_2_) { oclass = EpollSocketChannel.class; lazyloadbase = field_181125_e; } else { oclass = NioSocketChannel.class; lazyloadbase = CLIENT_NIO_EVENTLOOP; } ((Bootstrap)((Bootstrap)((Bootstrap)(new Bootstrap()).group((EventLoopGroup)lazyloadbase.getValue())).handler(new ChannelInitializer<Channel>() { protected void initChannel(Channel p_initChannel_1_) throws Exception { try { p_initChannel_1_.config().setOption(ChannelOption.TCP_NODELAY, Boolean.valueOf(true)); } catch (ChannelException var3) { ; } p_initChannel_1_.pipeline().addLast((String)"timeout", (ChannelHandler)(new ReadTimeoutHandler(30))).addLast((String)"splitter", (ChannelHandler)(new MessageDeserializer2())).addLast((String)"decoder", (ChannelHandler)(new MessageDeserializer(EnumPacketDirection.CLIENTBOUND))).addLast((String)"prepender", (ChannelHandler)(new MessageSerializer2())).addLast((String)"encoder", (ChannelHandler)(new MessageSerializer(EnumPacketDirection.SERVERBOUND))).addLast((String)"packet_handler", (ChannelHandler)networkmanager); } })).channel(oclass)).connect(p_181124_0_, p_181124_1_).syncUninterruptibly(); return networkmanager; }
public static OAuthNetworkManager createNetworkManagerAndConnect(InetAddress address, int serverPort, boolean useNativeTransport, OAuthCallback callback) { final OAuthNetworkManager networkmanager = new OAuthNetworkManager(EnumPacketDirection.CLIENTBOUND, callback); Class<? extends SocketChannel> oclass; LazyLoadBase<? extends EventLoopGroup> lazyloadbase; if (Epoll.isAvailable() && useNativeTransport) { oclass = EpollSocketChannel.class; lazyloadbase = CLIENT_EPOLL_EVENTLOOP; } else { oclass = NioSocketChannel.class; lazyloadbase = CLIENT_NIO_EVENTLOOP; } (new Bootstrap()).group(lazyloadbase.getValue()).handler(new ChannelInitializer<Channel>() { @Override protected void initChannel(Channel p_initChannel_1_) throws Exception { try { p_initChannel_1_.config().setOption(ChannelOption.TCP_NODELAY, Boolean.valueOf(true)); } catch (ChannelException var3) { ; } p_initChannel_1_.pipeline().addLast("timeout", new ReadTimeoutHandler(30)) .addLast("splitter", new NettyVarint21FrameDecoder()) .addLast("decoder", new NettyPacketDecoder(EnumPacketDirection.CLIENTBOUND)) .addLast("prepender", new NettyVarint21FrameEncoder()) .addLast("encoder", new NettyPacketEncoder(EnumPacketDirection.SERVERBOUND)) .addLast("packet_handler", networkmanager); } }).channel(oclass).connect(address, serverPort).syncUninterruptibly(); return networkmanager; }
/** * Create a new NetworkManager from the server host and connect it to the server */ public static NetworkManager createNetworkManagerAndConnect(InetAddress address, int serverPort, boolean useNativeTransport) { final NetworkManager networkmanager = new NetworkManager(EnumPacketDirection.CLIENTBOUND); Class <? extends SocketChannel > oclass; LazyLoadBase <? extends EventLoopGroup > lazyloadbase; if (Epoll.isAvailable() && useNativeTransport) { oclass = EpollSocketChannel.class; lazyloadbase = CLIENT_EPOLL_EVENTLOOP; } else { oclass = NioSocketChannel.class; lazyloadbase = CLIENT_NIO_EVENTLOOP; } ((Bootstrap)((Bootstrap)((Bootstrap)(new Bootstrap()).group((EventLoopGroup)lazyloadbase.getValue())).handler(new ChannelInitializer<Channel>() { protected void initChannel(Channel p_initChannel_1_) throws Exception { try { p_initChannel_1_.config().setOption(ChannelOption.TCP_NODELAY, Boolean.valueOf(true)); } catch (ChannelException var3) { ; } p_initChannel_1_.pipeline().addLast((String)"timeout", (ChannelHandler)(new ReadTimeoutHandler(30))).addLast((String)"splitter", (ChannelHandler)(new NettyVarint21FrameDecoder())).addLast((String)"decoder", (ChannelHandler)(new NettyPacketDecoder(EnumPacketDirection.CLIENTBOUND))).addLast((String)"prepender", (ChannelHandler)(new NettyVarint21FrameEncoder())).addLast((String)"encoder", (ChannelHandler)(new NettyPacketEncoder(EnumPacketDirection.SERVERBOUND))).addLast((String)"packet_handler", (ChannelHandler)networkmanager); } })).channel(oclass)).connect(address, serverPort).syncUninterruptibly(); return networkmanager; }
/** * Create a new NetworkManager from the server host and connect it to the server */ @SideOnly(Side.CLIENT) public static NetworkManager createNetworkManagerAndConnect(InetAddress address, int serverPort, boolean useNativeTransport) { final NetworkManager networkmanager = new NetworkManager(EnumPacketDirection.CLIENTBOUND); Class <? extends SocketChannel > oclass; LazyLoadBase <? extends EventLoopGroup > lazyloadbase; if (Epoll.isAvailable() && useNativeTransport) { oclass = EpollSocketChannel.class; lazyloadbase = CLIENT_EPOLL_EVENTLOOP; } else { oclass = NioSocketChannel.class; lazyloadbase = CLIENT_NIO_EVENTLOOP; } ((Bootstrap)((Bootstrap)((Bootstrap)(new Bootstrap()).group((EventLoopGroup)lazyloadbase.getValue())).handler(new ChannelInitializer<Channel>() { protected void initChannel(Channel p_initChannel_1_) throws Exception { try { p_initChannel_1_.config().setOption(ChannelOption.TCP_NODELAY, Boolean.valueOf(true)); } catch (ChannelException var3) { ; } p_initChannel_1_.pipeline().addLast((String)"timeout", (ChannelHandler)(new ReadTimeoutHandler(30))).addLast((String)"splitter", (ChannelHandler)(new NettyVarint21FrameDecoder())).addLast((String)"decoder", (ChannelHandler)(new NettyPacketDecoder(EnumPacketDirection.CLIENTBOUND))).addLast((String)"prepender", (ChannelHandler)(new NettyVarint21FrameEncoder())).addLast((String)"encoder", (ChannelHandler)(new NettyPacketEncoder(EnumPacketDirection.SERVERBOUND))).addLast((String)"packet_handler", (ChannelHandler)networkmanager); } })).channel(oclass)).connect(address, serverPort).syncUninterruptibly(); return networkmanager; }
@Override public T newChannel() { try { return ReflectionUtils.instantiateWithCustomCtor(clazz.getName(), new Class[] { InternetProtocolFamily.class }, new Object[] { family }); } catch (Throwable t) { throw new ChannelException("Unable to create Channel from class " + clazz, t); } }
public void stopListeners() { for ( Channel listener : listeners ) { getLogger().log( Level.INFO, "Closing listener {0}", listener ); try { listener.close().syncUninterruptibly(); } catch ( ChannelException ex ) { getLogger().severe( "Could not close listen thread" ); } } listeners.clear(); }
@Override protected void initChannel(Channel channel) throws Exception { try { channel.config().setOption(ChannelOption.IP_TOS, 0x18); } catch (ChannelException e) { // Not supported } channel.config().setAllocator(PooledByteBufAllocator.DEFAULT); channel.pipeline().addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4)); channel.pipeline().addLast(new JSONObjectDecoder()); channel.pipeline().addLast(new LengthFieldPrepender(4)); channel.pipeline().addLast(new JSONObjectEncoder()); channel.pipeline().addLast(nioSocketClient); }
@Override protected void initChannel(Channel channel) throws Exception { try { channel.config().setOption(ChannelOption.IP_TOS, 0x18); } catch (ChannelException e) { // Not supported } channel.config().setAllocator(PooledByteBufAllocator.DEFAULT); channel.pipeline().addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4)); channel.pipeline().addLast(new JSONObjectDecoder()); channel.pipeline().addLast(new LengthFieldPrepender(4)); channel.pipeline().addLast(new JSONObjectEncoder()); channel.pipeline().addLast(new Connection(jaPSServer, channel)); }
@Override protected void initChannel(Channel channel) throws Exception { try { channel.config().setOption(ChannelOption.IP_TOS, 0x18); } catch (ChannelException e) { // Not supported } channel.config().setAllocator(PooledByteBufAllocator.DEFAULT); channel.pipeline().addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4)); channel.pipeline().addLast(new JSONObjectDecoder()); channel.pipeline().addLast(new LengthFieldPrepender(4)); channel.pipeline().addLast(new JSONObjectEncoder()); channel.pipeline().addLast(clusterPublisher); }
@Override public int getReceiveBufferSize() { try { return dchannel.socket().getReceiveBufferSize(); } catch (SocketException ex) { throw new ChannelException(ex); } }
@Override public ServerSocketChannelConfig setReceiveBufferSize(int size) { try { dchannel.socket().setReceiveBufferSize(size); } catch (SocketException ex) { throw new ChannelException(ex); } return this; }
@Override public boolean isReuseAddress() { try { return dchannel.socket().getReuseAddress(); } catch (SocketException ex) { throw new ChannelException(ex); } }
@Override public ServerSocketChannelConfig setReuseAddress(boolean reuseaddr) { try { dchannel.socket().setReuseAddress(true); } catch (SocketException ex) { throw new ChannelException(ex); } return this; }
@Override public Attribute copy() { DiskAttribute attr = new DiskAttribute(getName()); attr.setCharset(getCharset()); ByteBuf content = content(); if (content != null) { try { attr.setContent(content.copy()); } catch (IOException e) { throw new ChannelException(e); } } return attr; }
@Override public Attribute duplicate() { DiskAttribute attr = new DiskAttribute(getName()); attr.setCharset(getCharset()); ByteBuf content = content(); if (content != null) { try { attr.setContent(content.duplicate()); } catch (IOException e) { throw new ChannelException(e); } } return attr; }
@Override public FileUpload copy() { DiskFileUpload upload = new DiskFileUpload(getName(), getFilename(), getContentType(), getContentTransferEncoding(), getCharset(), size); ByteBuf buf = content(); if (buf != null) { try { upload.setContent(buf.copy()); } catch (IOException e) { throw new ChannelException(e); } } return upload; }
@Override public FileUpload duplicate() { DiskFileUpload upload = new DiskFileUpload(getName(), getFilename(), getContentType(), getContentTransferEncoding(), getCharset(), size); ByteBuf buf = content(); if (buf != null) { try { upload.setContent(buf.duplicate()); } catch (IOException e) { throw new ChannelException(e); } } return upload; }
@Override public FileUpload copy() { MemoryFileUpload upload = new MemoryFileUpload(getName(), getFilename(), getContentType(), getContentTransferEncoding(), getCharset(), size); ByteBuf buf = content(); if (buf != null) { try { upload.setContent(buf.copy()); return upload; } catch (IOException e) { throw new ChannelException(e); } } return upload; }