@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 protected int doReadMessages(List<Object> buf) throws Exception { SctpChannel ch = javaChannel(); RecvByteBufAllocator.Handle allocHandle = this.allocHandle; if (allocHandle == null) { this.allocHandle = allocHandle = config().getRecvByteBufAllocator().newHandle(); } ByteBuf buffer = allocHandle.allocate(config().getAllocator()); boolean free = true; try { ByteBuffer data = buffer.internalNioBuffer(buffer.writerIndex(), buffer.writableBytes()); int pos = data.position(); MessageInfo messageInfo = ch.receive(data, null, notificationHandler); if (messageInfo == null) { return 0; } buf.add(new SctpMessage(messageInfo, buffer.writerIndex(buffer.writerIndex() + data.position() - pos))); free = false; return 1; } catch (Throwable cause) { PlatformDependent.throwException(cause); return -1; } finally { int bytesRead = buffer.readableBytes(); allocHandle.record(bytesRead); if (free) { buffer.release(); } } }
@Override protected int doReadMessages(List<Object> buf) throws Exception { SctpChannel ch = javaChannel(); RecvByteBufAllocator.Handle allocHandle = this.allocHandle; if (allocHandle == null) { this.allocHandle = allocHandle = config().getRecvByteBufAllocator().newHandle(); } ByteBuf buffer = allocHandle.allocate(config().getAllocator()); boolean free = true; try { ByteBuffer data = buffer.internalNioBuffer(buffer.writerIndex(), buffer.writableBytes()); int pos = data.position(); MessageInfo messageInfo = ch.receive(data, null, notificationHandler); if (messageInfo == null) { return 0; } buf.add(new SctpMessage(messageInfo, buffer.writerIndex(buffer.writerIndex() + (data.position() - pos)))); free = false; return 1; } catch (Throwable cause) { PlatformDependent.throwException(cause); return -1; } finally { int bytesRead = buffer.readableBytes(); allocHandle.record(bytesRead); if (free) { buffer.release(); } } }
@Override UkcpClientChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator);
@Override UkcpServerChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator);
@SuppressWarnings("deprecation") @Override protected int doReadMessages(List<Object> list) throws Exception { DatagramChannel javaChannel = javaChannel(); RecvByteBufAllocator.Handle allocatorHandle = unsafe().recvBufAllocHandle(); ByteBuf buffer = allocatorHandle.allocate(config.getAllocator()); allocatorHandle.attemptedBytesRead(buffer.writableBytes()); boolean freeBuffer = true; try { //read message ByteBuffer nioBuffer = buffer.internalNioBuffer(buffer.writerIndex(), buffer.writableBytes()); int nioPos = nioBuffer.position(); InetSocketAddress inetSocketAddress = (InetSocketAddress) javaChannel.receive(nioBuffer); if (inetSocketAddress == null) { return 0; } allocatorHandle.lastBytesRead(nioBuffer.position() - nioPos); buffer.writerIndex(buffer.writerIndex() + allocatorHandle.lastBytesRead()); //allocate new channel or use existing one and push message to it UdpChannel udpchannel = channels.get(inetSocketAddress); if ((udpchannel == null) || !udpchannel.isOpen()) { udpchannel = new UdpChannel(this, inetSocketAddress); channels.put(inetSocketAddress, udpchannel); list.add(udpchannel); udpchannel.addBuffer(buffer); freeBuffer = false; return 1; } else { udpchannel.addBuffer(buffer); freeBuffer = false; if (udpchannel.isRegistered()) { udpchannel.read(); } return 0; } } catch (Throwable t) { PlatformDependent.throwException(t); return -1; } finally { if (freeBuffer) { buffer.release(); } } }
@Override public ServerSocketChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator alloc) { super.setRecvByteBufAllocator(alloc); return this; }
public void setRecvBufAllocator(final RecvByteBufAllocator allocator) { options.put(ChannelOption.RCVBUF_ALLOCATOR, allocator); }
@Override UdtChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator);
@Override public UdtServerChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator) { super.setRecvByteBufAllocator(allocator); return this; }
@Override UdtServerChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator);
@Override public UdtChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator) { super.setRecvByteBufAllocator(allocator); return this; }
@Override SocketChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator);
@Override OioServerSocketChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator);
@Override public OioSocketChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator) { super.setRecvByteBufAllocator(allocator); return this; }
@Override public OioServerSocketChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator) { super.setRecvByteBufAllocator(allocator); return this; }
@Override OioSocketChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator);
@Override public SocketChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator) { super.setRecvByteBufAllocator(allocator); return this; }
@Override public ServerSocketChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator) { super.setRecvByteBufAllocator(allocator); return this; }
@Override DatagramChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator);
@Override public DatagramChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator) { super.setRecvByteBufAllocator(allocator); return this; }
@Override ServerSocketChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator);
@Override SctpChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator);
@Override public SctpServerChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator) { super.setRecvByteBufAllocator(allocator); return this; }
@Override protected int doReadMessages(List<Object> msgs) throws Exception { if (!readSelector.isOpen()) { return 0; } int readMessages = 0; final int selectedKeys = readSelector.select(SO_TIMEOUT); final boolean keysSelected = selectedKeys > 0; if (!keysSelected) { return readMessages; } Set<SelectionKey> reableKeys = readSelector.selectedKeys(); try { for (SelectionKey ignored : reableKeys) { RecvByteBufAllocator.Handle allocHandle = this.allocHandle; if (allocHandle == null) { this.allocHandle = allocHandle = config().getRecvByteBufAllocator().newHandle(); } ByteBuf buffer = allocHandle.allocate(config().getAllocator()); boolean free = true; try { ByteBuffer data = buffer.nioBuffer(buffer.writerIndex(), buffer.writableBytes()); MessageInfo messageInfo = ch.receive(data, null, notificationHandler); if (messageInfo == null) { return readMessages; } data.flip(); msgs.add(new SctpMessage(messageInfo, buffer.writerIndex(buffer.writerIndex() + data.remaining()))); free = false; readMessages ++; } catch (Throwable cause) { PlatformDependent.throwException(cause); } finally { int bytesRead = buffer.readableBytes(); allocHandle.record(bytesRead); if (free) { buffer.release(); } } } } finally { reableKeys.clear(); } return readMessages; }
@Override public SctpChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator) { super.setRecvByteBufAllocator(allocator); return this; }
@Override SctpServerChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator);
@Override RxtxChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator);
@Override public RxtxChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator) { super.setRecvByteBufAllocator(allocator); return this; }
@Override DomainSocketChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator);
@Override public EpollChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator) { super.setRecvByteBufAllocator(allocator); return this; }
@Override public EpollServerChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator) { super.setRecvByteBufAllocator(allocator); return this; }
@Override public EpollDomainSocketChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator) { super.setRecvByteBufAllocator(allocator); return this; }
@Override public EpollDatagramChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator) { super.setRecvByteBufAllocator(allocator); return this; }
@Override public EpollSocketChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator) { super.setRecvByteBufAllocator(allocator); return this; }
@Override public EpollServerSocketChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator) { super.setRecvByteBufAllocator(allocator); return this; }