Java 类io.netty.channel.socket.DatagramChannelConfig 实例源码

项目:netty4.0.27Learn    文件:NioDatagramChannelConfig.java   
@Override
public DatagramChannelConfig setInterface(InetAddress interfaceAddress) {
    try {
        setNetworkInterface(NetworkInterface.getByInetAddress(interfaceAddress));
    } catch (SocketException e) {
        throw new ChannelException(e);
    }
    return this;
}
项目:netty4.0.27Learn    文件:NioDatagramChannel.java   
@Override
protected int doReadMessages(List<Object> buf) throws Exception {
    DatagramChannel ch = javaChannel();
    DatagramChannelConfig config = config();
    RecvByteBufAllocator.Handle allocHandle = this.allocHandle;
    if (allocHandle == null) {
        this.allocHandle = allocHandle = config.getRecvByteBufAllocator().newHandle();
    }
    ByteBuf data = allocHandle.allocate(config.getAllocator());
    boolean free = true;
    try {
        ByteBuffer nioData = data.internalNioBuffer(data.writerIndex(), data.writableBytes());
        int pos = nioData.position();
        InetSocketAddress remoteAddress = (InetSocketAddress) ch.receive(nioData);
        if (remoteAddress == null) {
            return 0;
        }

        int readBytes = nioData.position() - pos;
        data.writerIndex(data.writerIndex() + readBytes);
        allocHandle.record(readBytes);

        buf.add(new DatagramPacket(data, localAddress(), remoteAddress));
        free = false;
        return 1;
    } catch (Throwable cause) {
        PlatformDependent.throwException(cause);
        return -1;
    }  finally {
        if (free) {
            data.release();
        }
    }
}
项目:netty4study    文件:NioDatagramChannelConfig.java   
@Override
public DatagramChannelConfig setInterface(InetAddress interfaceAddress) {
    try {
        setNetworkInterface(NetworkInterface.getByInetAddress(interfaceAddress));
    } catch (SocketException e) {
        throw new ChannelException(e);
    }
    return this;
}
项目:netty4study    文件:NioDatagramChannel.java   
@Override
protected int doReadMessages(List<Object> buf) throws Exception {
    DatagramChannel ch = javaChannel();
    DatagramChannelConfig config = config();
    RecvByteBufAllocator.Handle allocHandle = this.allocHandle;
    if (allocHandle == null) {
        this.allocHandle = allocHandle = config.getRecvByteBufAllocator().newHandle();
    }
    ByteBuf data = allocHandle.allocate(config.getAllocator());
    boolean free = true;
    try {
        ByteBuffer nioData = data.internalNioBuffer(data.writerIndex(), data.writableBytes());
        int pos = nioData.position();
        InetSocketAddress remoteAddress = (InetSocketAddress) ch.receive(nioData);
        if (remoteAddress == null) {
            return 0;
        }

        int readBytes = nioData.position() - pos;
        data.writerIndex(data.writerIndex() + readBytes);
        allocHandle.record(readBytes);

        buf.add(new DatagramPacket(data, localAddress(), remoteAddress));
        free = false;
        return 1;
    } catch (Throwable cause) {
        PlatformDependent.throwException(cause);
        return -1;
    }  finally {
        if (free) {
            data.release();
        }
    }
}
项目:netty-netty-5.0.0.Alpha1    文件:NioDatagramChannelConfig.java   
@Override
public DatagramChannelConfig setInterface(InetAddress interfaceAddress) {
    try {
        setNetworkInterface(NetworkInterface.getByInetAddress(interfaceAddress));
    } catch (SocketException e) {
        throw new ChannelException(e);
    }
    return this;
}
项目:netty-netty-5.0.0.Alpha1    文件:NioDatagramChannel.java   
@Override
protected int doReadMessages(List<Object> buf) throws Exception {
    DatagramChannel ch = javaChannel();
    DatagramChannelConfig config = config();
    RecvByteBufAllocator.Handle allocHandle = this.allocHandle;
    if (allocHandle == null) {
        this.allocHandle = allocHandle = config.getRecvByteBufAllocator().newHandle();
    }
    ByteBuf data = allocHandle.allocate(config.getAllocator());
    boolean free = true;
    try {
        ByteBuffer nioData = data.internalNioBuffer(data.writerIndex(), data.writableBytes());
        int pos = nioData.position();
        InetSocketAddress remoteAddress = (InetSocketAddress) ch.receive(nioData);
        if (remoteAddress == null) {
            return 0;
        }

        int readBytes = nioData.position() - pos;
        data.writerIndex(data.writerIndex() + readBytes);
        allocHandle.record(readBytes);

        buf.add(new DatagramPacket(data, localAddress(), remoteAddress));
        free = false;
        return 1;
    } catch (Throwable cause) {
        PlatformDependent.throwException(cause);
        return -1;
    }  finally {
        if (free) {
            data.release();
        }
    }
}
项目:netty4.0.27Learn    文件:OioDatagramChannel.java   
@Override
public DatagramChannelConfig config() {
    return config;
}
项目:netty4.0.27Learn    文件:NioDatagramChannelConfig.java   
@Override
public DatagramChannelConfig setTimeToLive(int ttl) {
    setOption0(IP_MULTICAST_TTL, ttl);
    return this;
}
项目:netty4.0.27Learn    文件:NioDatagramChannelConfig.java   
@Override
public DatagramChannelConfig setNetworkInterface(NetworkInterface networkInterface) {
    setOption0(IP_MULTICAST_IF, networkInterface);
    return this;
}
项目:netty4.0.27Learn    文件:NioDatagramChannelConfig.java   
@Override
public DatagramChannelConfig setLoopbackModeDisabled(boolean loopbackModeDisabled) {
    setOption0(IP_MULTICAST_LOOP, loopbackModeDisabled);
    return this;
}
项目:netty4.0.27Learn    文件:NioDatagramChannelConfig.java   
@Override
public DatagramChannelConfig setAutoRead(boolean autoRead) {
    super.setAutoRead(autoRead);
    return this;
}
项目:netty4.0.27Learn    文件:NioDatagramChannel.java   
@Override
public DatagramChannelConfig config() {
    return config;
}
项目:netty4.0.27Learn    文件:EpollDatagramChannelConfig.java   
@Override
public DatagramChannelConfig setLoopbackModeDisabled(boolean loopbackModeDisabled) {
    throw new UnsupportedOperationException("Multicast not supported");
}
项目:netty4study    文件:OioDatagramChannel.java   
@Override
public DatagramChannelConfig config() {
    return config;
}
项目:netty4study    文件:NioDatagramChannelConfig.java   
@Override
public DatagramChannelConfig setTimeToLive(int ttl) {
    setOption0(IP_MULTICAST_TTL, ttl);
    return this;
}
项目:netty4study    文件:NioDatagramChannelConfig.java   
@Override
public DatagramChannelConfig setNetworkInterface(NetworkInterface networkInterface) {
    setOption0(IP_MULTICAST_IF, networkInterface);
    return this;
}
项目:netty4study    文件:NioDatagramChannelConfig.java   
@Override
public DatagramChannelConfig setLoopbackModeDisabled(boolean loopbackModeDisabled) {
    setOption0(IP_MULTICAST_LOOP, loopbackModeDisabled);
    return this;
}
项目:netty4study    文件:NioDatagramChannel.java   
@Override
public DatagramChannelConfig config() {
    return config;
}
项目:netty-netty-5.0.0.Alpha1    文件:OioDatagramChannel.java   
@Override
public DatagramChannelConfig config() {
    return config;
}
项目:netty-netty-5.0.0.Alpha1    文件:NioDatagramChannelConfig.java   
@Override
public DatagramChannelConfig setTimeToLive(int ttl) {
    setOption0(IP_MULTICAST_TTL, ttl);
    return this;
}
项目:netty-netty-5.0.0.Alpha1    文件:NioDatagramChannelConfig.java   
@Override
public DatagramChannelConfig setNetworkInterface(NetworkInterface networkInterface) {
    setOption0(IP_MULTICAST_IF, networkInterface);
    return this;
}
项目:netty-netty-5.0.0.Alpha1    文件:NioDatagramChannelConfig.java   
@Override
public DatagramChannelConfig setLoopbackModeDisabled(boolean loopbackModeDisabled) {
    setOption0(IP_MULTICAST_LOOP, loopbackModeDisabled);
    return this;
}
项目:netty-netty-5.0.0.Alpha1    文件:NioDatagramChannel.java   
@Override
public DatagramChannelConfig config() {
    return config;
}