@Override public DatagramChannelConfig setInterface(InetAddress interfaceAddress) { try { setNetworkInterface(NetworkInterface.getByInetAddress(interfaceAddress)); } catch (SocketException e) { throw new ChannelException(e); } return this; }
@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(); } } }
@Override public DatagramChannelConfig config() { return config; }
@Override public DatagramChannelConfig setTimeToLive(int ttl) { setOption0(IP_MULTICAST_TTL, ttl); return this; }
@Override public DatagramChannelConfig setNetworkInterface(NetworkInterface networkInterface) { setOption0(IP_MULTICAST_IF, networkInterface); return this; }
@Override public DatagramChannelConfig setLoopbackModeDisabled(boolean loopbackModeDisabled) { setOption0(IP_MULTICAST_LOOP, loopbackModeDisabled); return this; }
@Override public DatagramChannelConfig setAutoRead(boolean autoRead) { super.setAutoRead(autoRead); return this; }
@Override public DatagramChannelConfig setLoopbackModeDisabled(boolean loopbackModeDisabled) { throw new UnsupportedOperationException("Multicast not supported"); }