Refine search
final ByteBufAllocator allocator = config.getAllocator(); allocHandle.reset(config); readReadyBefore(); do { data = allocHandle.allocate(allocator); allocHandle.attemptedBytesRead(data.writableBytes()); final DatagramSocketAddress remoteAddress; if (data.hasMemoryAddress()) { remoteAddress = socket.recvFromAddress(data.memoryAddress(), data.writerIndex(), data.capacity()); } else { new DatagramPacket(data, (InetSocketAddress) localAddress(), remoteAddress));
@Override @SuppressWarnings("deprecation") public boolean isActive() { DatagramChannel ch = javaChannel(); return ch.isOpen() && ( config.getOption(ChannelOption.DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION) && isRegistered() || ch.socket().isBound()); }
public void configure(DatagramChannel channel, DatagramSocketOptions options) { channel.config().setAllocator(PartialPooledByteBufAllocator.INSTANCE); 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().setOption(ChannelOption.SO_REUSEADDR, options.isReuseAddress()); if (options.getTrafficClass() != -1) { channel.config().setTrafficClass(options.getTrafficClass()); } channel.config().setBroadcast(options.isBroadcast()); if (this == Transport.JDK) { 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()); } } } }
final RecvByteBufAllocator.Handle allocHandle = unsafe().recvBufAllocHandle(); ByteBuf data = config.getAllocator().heapBuffer(allocHandle.guess()); boolean free = true; try { tmpPacket.setData(data.array(), data.arrayOffset(), data.capacity()); socket.receive(tmpPacket); buf.add(new DatagramPacket(data.writerIndex(allocHandle.lastBytesRead()), localAddress(), remoteAddr)); free = false; return 1;
@Override protected int doReadMessages(List<Object> buf) throws Exception { DatagramChannel ch = javaChannel(); DatagramChannelConfig config = config(); RecvByteBufAllocator.Handle allocHandle = unsafe().recvBufAllocHandle(); ByteBuf data = allocHandle.allocate(config.getAllocator()); allocHandle.attemptedBytesRead(data.writableBytes()); 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; } allocHandle.lastBytesRead(nioData.position() - pos); buf.add(new DatagramPacket(data.writerIndex(data.writerIndex() + allocHandle.lastBytesRead()), localAddress(), remoteAddress)); free = false; return 1; } catch (Throwable cause) { PlatformDependent.throwException(cause); return -1; } finally { if (free) { data.release(); } } }
final NioDatagramChannel ch = new NioDatagramChannel(); DatagramChannelConfig config = ch.config(); config.setReceiveBufferSize(options.rcvbuf()); config.setSendBufferSize(options.sndbuf()); config.setReuseAddress(options.reuseAddr()); config.setNetworkInterface(multicastInterface);
/** * Join a multicast group. * * @param multicastAddress multicast address of the group to join * * @return a {@link Publisher} that will be complete when the group has been joined */ @Override public Mono<Void> join(final InetAddress multicastAddress, NetworkInterface iface) { if (null == iface && null != datagramChannel.config().getNetworkInterface()) { iface = datagramChannel.config().getNetworkInterface(); } final ChannelFuture future; if (null != iface) { future = datagramChannel.joinGroup(new InetSocketAddress(multicastAddress, datagramChannel.localAddress() .getPort()), iface); } else { future = datagramChannel.joinGroup(multicastAddress); } return FutureMono.from(future) .doOnSuccess(v -> log.info(format(future.channel(), "JOIN {}"), multicastAddress)); }
ch.config().setRecvByteBufAllocator(new FixedRecvByteBufAllocator(maxPayloadSize));
final RecvByteBufAllocator.Handle allocHandle = unsafe().recvBufAllocHandle(); ByteBuf data = config.getAllocator().heapBuffer(allocHandle.guess()); boolean free = true; try { tmpPacket.setData(data.array(), data.arrayOffset(), data.capacity()); socket.receive(tmpPacket); buf.add(new DatagramPacket(data.writerIndex(allocHandle.lastBytesRead()), localAddress(), remoteAddr)); free = false; return 1;
@Override protected int doReadMessages(List<Object> buf) throws Exception { DatagramChannel ch = javaChannel(); DatagramChannelConfig config = config(); RecvByteBufAllocator.Handle allocHandle = unsafe().recvBufAllocHandle(); ByteBuf data = allocHandle.allocate(config.getAllocator()); allocHandle.attemptedBytesRead(data.writableBytes()); 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; } allocHandle.lastBytesRead(nioData.position() - pos); buf.add(new DatagramPacket(data.writerIndex(data.writerIndex() + allocHandle.lastBytesRead()), localAddress(), remoteAddress)); free = false; return 1; } catch (Throwable cause) { PlatformDependent.throwException(cause); return -1; } finally { if (free) { data.release(); } } }
/** * Leave a multicast group. * * @param multicastAddress multicast address of the group to leave * * @return a {@link Publisher} that will be complete when the group has been left */ @Override public Mono<Void> leave(final InetAddress multicastAddress, NetworkInterface iface) { if (null == iface && null != datagramChannel.config().getNetworkInterface()) { iface = datagramChannel.config().getNetworkInterface(); } final ChannelFuture future; if (null != iface) { future = datagramChannel.leaveGroup(new InetSocketAddress(multicastAddress, datagramChannel.localAddress() .getPort()), iface); } else { future = datagramChannel.leaveGroup(multicastAddress); } return FutureMono.from(future) .doOnSuccess(v -> log.info(format(future.channel(), "JOIN {}"), multicastAddress)); }
ch.config().setRecvByteBufAllocator(new FixedRecvByteBufAllocator(maxPayloadSize));
final ByteBufAllocator allocator = config.getAllocator(); allocHandle.reset(config); epollInBefore(); do { data = allocHandle.allocate(allocator); allocHandle.attemptedBytesRead(data.writableBytes()); final DatagramSocketAddress remoteAddress; if (data.hasMemoryAddress()) { remoteAddress = socket.recvFromAddress(data.memoryAddress(), data.writerIndex(), data.capacity()); } else { new DatagramPacket(data, localAddress, remoteAddress));
final RecvByteBufAllocator.Handle allocHandle = unsafe().recvBufAllocHandle(); ByteBuf data = config.getAllocator().heapBuffer(allocHandle.guess()); boolean free = true; try { tmpPacket.setData(data.array(), data.arrayOffset(), data.capacity()); socket.receive(tmpPacket); buf.add(new DatagramPacket(data.writerIndex(allocHandle.lastBytesRead()), localAddress(), remoteAddr)); free = false; return 1;
@Override protected int doReadMessages(List<Object> buf) throws Exception { DatagramChannel ch = javaChannel(); DatagramChannelConfig config = config(); RecvByteBufAllocator.Handle allocHandle = unsafe().recvBufAllocHandle(); ByteBuf data = allocHandle.allocate(config.getAllocator()); allocHandle.attemptedBytesRead(data.writableBytes()); 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; } allocHandle.lastBytesRead(nioData.position() - pos); buf.add(new DatagramPacket(data.writerIndex(data.writerIndex() + allocHandle.lastBytesRead()), localAddress(), remoteAddress)); free = false; return 1; } catch (Throwable cause) { PlatformDependent.throwException(cause); return -1; } finally { if (free) { data.release(); } } }
public void configure(DatagramChannel channel, DatagramSocketOptions options) { channel.config().setAllocator(PartialPooledByteBufAllocator.INSTANCE); 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().setOption(ChannelOption.SO_REUSEADDR, options.isReuseAddress()); if (options.getTrafficClass() != -1) { channel.config().setTrafficClass(options.getTrafficClass()); } channel.config().setBroadcast(options.isBroadcast()); if (this == Transport.JDK) { 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()); } } } }
@Override @SuppressWarnings("deprecation") public boolean isActive() { DatagramChannel ch = javaChannel(); return ch.isOpen() && ( config.getOption(ChannelOption.DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION) && isRegistered() || ch.socket().isBound()); }
/** * Leave a multicast group. * * @param multicastAddress multicast address of the group to leave * * @return a {@link Publisher} that will be complete when the group has been left */ @Override public Mono<Void> leave(final InetAddress multicastAddress, NetworkInterface iface) { if (null == iface && null != datagramChannel.config().getNetworkInterface()) { iface = datagramChannel.config().getNetworkInterface(); } final ChannelFuture future; if (null != iface) { future = datagramChannel.leaveGroup(new InetSocketAddress(multicastAddress, datagramChannel.localAddress() .getPort()), iface); } else { future = datagramChannel.leaveGroup(multicastAddress); } return FutureMono.from(future) .doOnSuccess(v -> log.info(format(future.channel(), "JOIN {}"), multicastAddress)); }
ch.config().setRecvByteBufAllocator(new FixedRecvByteBufAllocator(maxPayloadSize));
final ByteBufAllocator allocator = config.getAllocator(); allocHandle.reset(config); readReadyBefore(); do { data = allocHandle.allocate(allocator); allocHandle.attemptedBytesRead(data.writableBytes()); final DatagramSocketAddress remoteAddress; if (data.hasMemoryAddress()) { remoteAddress = socket.recvFromAddress(data.memoryAddress(), data.writerIndex(), data.capacity()); } else { new DatagramPacket(data, (InetSocketAddress) localAddress(), remoteAddress));