Home / Function/ readReady() — netty Function Reference

readReady() — netty Function Reference

Architecture documentation for the readReady() function in KQueueDatagramChannel.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  7d73a1ce_8dab_4b77_c0bb_3c2a989b5b4e["readReady()"]
  9313a9ce_3971_e082_2088_9dd72ef133fe["KQueueDatagramChannelUnsafe"]
  7d73a1ce_8dab_4b77_c0bb_3c2a989b5b4e -->|defined in| 9313a9ce_3971_e082_2088_9dd72ef133fe
  d11c714d_c055_87f1_26ca_7083c4f46546["isConnected()"]
  7d73a1ce_8dab_4b77_c0bb_3c2a989b5b4e -->|calls| d11c714d_c055_87f1_26ca_7083c4f46546
  style 7d73a1ce_8dab_4b77_c0bb_3c2a989b5b4e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

transport-classes-kqueue/src/main/java/io/netty/channel/kqueue/KQueueDatagramChannel.java lines 393–491

        @Override
        void readReady(KQueueRecvByteAllocatorHandle allocHandle) {
            assert eventLoop().inEventLoop();
            final DatagramChannelConfig config = config();
            if (shouldBreakReadReady(config)) {
                clearReadFilter0();
                return;
            }
            final ChannelPipeline pipeline = pipeline();
            final ByteBufAllocator allocator = config.getAllocator();
            allocHandle.reset(config);

            Throwable exception = null;
            try {
                ByteBuf byteBuf = null;
                try {
                    boolean connected = isConnected();
                    do {
                        byteBuf = allocHandle.allocate(allocator);
                        allocHandle.attemptedBytesRead(byteBuf.writableBytes());

                        final DatagramPacket packet;
                        if (connected) {
                            try {
                                allocHandle.lastBytesRead(doReadBytes(byteBuf));
                            } catch (Errors.NativeIoException e) {
                                // We need to correctly translate connect errors to match NIO behaviour.
                                if (e.expectedErr() == Errors.ERROR_ECONNREFUSED_NEGATIVE) {
                                    PortUnreachableException error = new PortUnreachableException(e.getMessage());
                                    error.initCause(e);
                                    throw error;
                                }
                                throw e;
                            }
                            if (allocHandle.lastBytesRead() <= 0) {
                                // nothing was read, release the buffer.
                                byteBuf.release();
                                byteBuf = null;
                                break;
                            }
                            packet = new DatagramPacket(byteBuf,
                                    (InetSocketAddress) localAddress(), (InetSocketAddress) remoteAddress());
                        } else {
                            final DatagramSocketAddress remoteAddress;
                            if (byteBuf.hasMemoryAddress()) {
                                // has a memory address so use optimized call
                                remoteAddress = socket.recvFromAddress(byteBuf.memoryAddress(), byteBuf.writerIndex(),
                                        byteBuf.capacity());
                            } else {
                                ByteBuffer nioData = byteBuf.internalNioBuffer(
                                        byteBuf.writerIndex(), byteBuf.writableBytes());
                                remoteAddress = socket.recvFrom(nioData, nioData.position(), nioData.limit());
                            }

                            if (remoteAddress == null) {
                                allocHandle.lastBytesRead(-1);
                                byteBuf.release();
                                byteBuf = null;
                                break;
                            }
                            InetSocketAddress localAddress = remoteAddress.localAddress();
                            if (localAddress == null) {
                                localAddress = (InetSocketAddress) localAddress();
                            }
                            allocHandle.lastBytesRead(remoteAddress.receivedAmount());
                            byteBuf.writerIndex(byteBuf.writerIndex() + allocHandle.lastBytesRead());

                            packet = new DatagramPacket(byteBuf, localAddress, remoteAddress);
                        }

                        allocHandle.incMessagesRead(1);

                        readPending = false;
                        pipeline.fireChannelRead(packet);

                        byteBuf = null;

                    // We use the TRUE_SUPPLIER as it is also ok to read less then what we did try to read (as long
                    // as we read anything).
                    } while (allocHandle.continueReading(UncheckedBooleanSupplier.TRUE_SUPPLIER));
                } catch (Throwable t) {

Domain

Subdomains

Frequently Asked Questions

What does readReady() do?
readReady() is a function in the netty codebase, defined in transport-classes-kqueue/src/main/java/io/netty/channel/kqueue/KQueueDatagramChannel.java.
Where is readReady() defined?
readReady() is defined in transport-classes-kqueue/src/main/java/io/netty/channel/kqueue/KQueueDatagramChannel.java at line 393.
What does readReady() call?
readReady() calls 1 function(s): isConnected.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free