Home / Function/ read() — netty Function Reference

read() — netty Function Reference

Architecture documentation for the read() function in AbstractNioByteChannel.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  eafbe12c_ddc4_fdfc_7207_cbb526f9b297["read()"]
  f52609a8_b5d5_f9b7_0a87_06421659d477["NioByteUnsafe"]
  eafbe12c_ddc4_fdfc_7207_cbb526f9b297 -->|defined in| f52609a8_b5d5_f9b7_0a87_06421659d477
  dc410111_84b8_c71e_6712_87ccf53c2adc["shouldBreakReadReady()"]
  eafbe12c_ddc4_fdfc_7207_cbb526f9b297 -->|calls| dc410111_84b8_c71e_6712_87ccf53c2adc
  7fd465b7_882a_8f95_e0fd_40c2161616bb["doReadBytes()"]
  eafbe12c_ddc4_fdfc_7207_cbb526f9b297 -->|calls| 7fd465b7_882a_8f95_e0fd_40c2161616bb
  216aa50a_4b2e_d203_0a18_d38f61e1dd7e["closeOnRead()"]
  eafbe12c_ddc4_fdfc_7207_cbb526f9b297 -->|calls| 216aa50a_4b2e_d203_0a18_d38f61e1dd7e
  a63e69b1_c5a7_0e05_79bc_163803b55680["handleReadException()"]
  eafbe12c_ddc4_fdfc_7207_cbb526f9b297 -->|calls| a63e69b1_c5a7_0e05_79bc_163803b55680
  style eafbe12c_ddc4_fdfc_7207_cbb526f9b297 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

transport/src/main/java/io/netty/channel/nio/AbstractNioByteChannel.java lines 144–199

        @Override
        public final void read() {
            final ChannelConfig config = config();
            if (shouldBreakReadReady(config)) {
                clearReadPending();
                return;
            }
            final ChannelPipeline pipeline = pipeline();
            final ByteBufAllocator allocator = config.getAllocator();
            final RecvByteBufAllocator.Handle allocHandle = recvBufAllocHandle();
            allocHandle.reset(config);

            ByteBuf byteBuf = null;
            boolean close = false;
            try {
                do {
                    byteBuf = allocHandle.allocate(allocator);
                    allocHandle.lastBytesRead(doReadBytes(byteBuf));
                    if (allocHandle.lastBytesRead() <= 0) {
                        // nothing was read. release the buffer.
                        byteBuf.release();
                        byteBuf = null;
                        close = allocHandle.lastBytesRead() < 0;
                        if (close) {
                            // There is nothing left to read as we received an EOF.
                            readPending = false;
                        }
                        break;
                    }

                    allocHandle.incMessagesRead(1);
                    readPending = false;
                    pipeline.fireChannelRead(byteBuf);
                    byteBuf = null;
                } while (allocHandle.continueReading());

                allocHandle.readComplete();
                pipeline.fireChannelReadComplete();

                if (close) {
                    closeOnRead(pipeline);
                }
            } catch (Throwable t) {
                handleReadException(pipeline, byteBuf, t, close, allocHandle);
            } finally {
                // Check if there is a readPending which was not processed yet.
                // This could be for two reasons:
                // * The user called Channel.read() or ChannelHandlerContext.read() in channelRead(...) method
                // * The user called Channel.read() or ChannelHandlerContext.read() in channelReadComplete(...) method
                //
                // See https://github.com/netty/netty/issues/2254
                if (!readPending && !config.isAutoRead()) {
                    removeReadOp();
                }
            }
        }

Domain

Subdomains

Frequently Asked Questions

What does read() do?
read() is a function in the netty codebase, defined in transport/src/main/java/io/netty/channel/nio/AbstractNioByteChannel.java.
Where is read() defined?
read() is defined in transport/src/main/java/io/netty/channel/nio/AbstractNioByteChannel.java at line 144.
What does read() call?
read() calls 4 function(s): closeOnRead, doReadBytes, handleReadException, shouldBreakReadReady.

Analyze Your Own Codebase

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

Try Supermodel Free