Search in sources :

Example 6 with FixedRecvByteBufAllocator

use of io.netty.channel.FixedRecvByteBufAllocator in project vert.x by eclipse.

the class NetClientImpl method applyConnectionOptions.

private void applyConnectionOptions(Bootstrap bootstrap) {
    if (options.getLocalAddress() != null) {
        bootstrap.localAddress(options.getLocalAddress(), 0);
    }
    bootstrap.option(ChannelOption.TCP_NODELAY, options.isTcpNoDelay());
    if (options.getSendBufferSize() != -1) {
        bootstrap.option(ChannelOption.SO_SNDBUF, options.getSendBufferSize());
    }
    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());
}
Also used : FixedRecvByteBufAllocator(io.netty.channel.FixedRecvByteBufAllocator)

Example 7 with FixedRecvByteBufAllocator

use of io.netty.channel.FixedRecvByteBufAllocator in project vert.x by eclipse.

the class DatagramSocketImpl method createChannel.

private static NioDatagramChannel createChannel(io.vertx.core.datagram.impl.InternetProtocolFamily family, DatagramSocketOptions options) {
    NioDatagramChannel channel;
    if (family == null) {
        channel = new NioDatagramChannel();
    } else {
        switch(family) {
            case IPv4:
                channel = new NioDatagramChannel(InternetProtocolFamily.IPv4);
                break;
            case IPv6:
                channel = new NioDatagramChannel(InternetProtocolFamily.IPv6);
                break;
            default:
                channel = new NioDatagramChannel();
        }
    }
    if (options.getSendBufferSize() != -1) {
        channel.config().setSendBufferSize(options.getSendBufferSize());
    }
    if (options.getReceiveBufferSize() != -1) {
        channel.config().setReceiveBufferSize(options.getReceiveBufferSize());
        channel.config().setRecvByteBufAllocator(new FixedRecvByteBufAllocator(options.getReceiveBufferSize()));
    }
    channel.config().setReuseAddress(options.isReuseAddress());
    if (options.getTrafficClass() != -1) {
        channel.config().setTrafficClass(options.getTrafficClass());
    }
    channel.config().setBroadcast(options.isBroadcast());
    channel.config().setLoopbackModeDisabled(options.isLoopbackModeDisabled());
    if (options.getMulticastTimeToLive() != -1) {
        channel.config().setTimeToLive(options.getMulticastTimeToLive());
    }
    if (options.getMulticastNetworkInterface() != null) {
        try {
            channel.config().setNetworkInterface(NetworkInterface.getByName(options.getMulticastNetworkInterface()));
        } catch (SocketException e) {
            throw new IllegalArgumentException("Could not find network interface with name " + options.getMulticastNetworkInterface());
        }
    }
    return channel;
}
Also used : NioDatagramChannel(io.netty.channel.socket.nio.NioDatagramChannel) FixedRecvByteBufAllocator(io.netty.channel.FixedRecvByteBufAllocator)

Aggregations

FixedRecvByteBufAllocator (io.netty.channel.FixedRecvByteBufAllocator)7 NioDatagramChannel (io.netty.channel.socket.nio.NioDatagramChannel)2 Bootstrap (io.netty.bootstrap.Bootstrap)1 ChannelFuture (io.netty.channel.ChannelFuture)1 EventLoopGroup (io.netty.channel.EventLoopGroup)1 EpollDatagramChannel (io.netty.channel.epoll.EpollDatagramChannel)1 DatagramChannel (io.netty.channel.socket.DatagramChannel)1 InetSocketAddress (java.net.InetSocketAddress)1 Map (java.util.Map)1 SubnetUtils (org.apache.camel.component.netty4.util.SubnetUtils)1 JndiRegistry (org.apache.camel.impl.JndiRegistry)1