Home / Function/ read() — netty Function Reference

read() — netty Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  fdaeb6e3_b1a0_895b_8d25_cbfe40e8b726["read()"]
  8eba98e8_3c2a_def1_f7a1_96325e814899["NioMessageUnsafe"]
  fdaeb6e3_b1a0_895b_8d25_cbfe40e8b726 -->|defined in| 8eba98e8_3c2a_def1_f7a1_96325e814899
  913da49c_1ef4_7f1a_749e_fe98a9bad805["doReadMessages()"]
  fdaeb6e3_b1a0_895b_8d25_cbfe40e8b726 -->|calls| 913da49c_1ef4_7f1a_749e_fe98a9bad805
  30f77b55_de75_10f5_d16f_00f319f9f672["continueReading()"]
  fdaeb6e3_b1a0_895b_8d25_cbfe40e8b726 -->|calls| 30f77b55_de75_10f5_d16f_00f319f9f672
  41047431_2be4_b405_cf1b_592f5cad83f1["closeOnReadError()"]
  fdaeb6e3_b1a0_895b_8d25_cbfe40e8b726 -->|calls| 41047431_2be4_b405_cf1b_592f5cad83f1
  style fdaeb6e3_b1a0_895b_8d25_cbfe40e8b726 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

transport/src/main/java/io/netty/channel/nio/AbstractNioMessageChannel.java lines 69–129

        @Override
        public void read() {
            assert eventLoop().inEventLoop();
            final ChannelConfig config = config();
            final ChannelPipeline pipeline = pipeline();
            final RecvByteBufAllocator.Handle allocHandle = unsafe().recvBufAllocHandle();
            allocHandle.reset(config);

            boolean closed = false;
            Throwable exception = null;
            try {
                try {
                    do {
                        int localRead = doReadMessages(readBuf);
                        if (localRead == 0) {
                            break;
                        }
                        if (localRead < 0) {
                            closed = true;
                            break;
                        }

                        allocHandle.incMessagesRead(localRead);
                    } while (continueReading(allocHandle));
                } catch (Throwable t) {
                    exception = t;
                }

                int size = readBuf.size();
                for (int i = 0; i < size; i ++) {
                    readPending = false;
                    pipeline.fireChannelRead(readBuf.get(i));
                }
                readBuf.clear();
                allocHandle.readComplete();
                pipeline.fireChannelReadComplete();

                if (exception != null) {
                    closed = closeOnReadError(exception);

                    pipeline.fireExceptionCaught(exception);
                }

                if (closed) {
                    inputShutdown = true;
                    if (isOpen()) {
                        close(voidPromise());
                    }
                }
            } 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/AbstractNioMessageChannel.java.
Where is read() defined?
read() is defined in transport/src/main/java/io/netty/channel/nio/AbstractNioMessageChannel.java at line 69.
What does read() call?
read() calls 3 function(s): closeOnReadError, continueReading, doReadMessages.

Analyze Your Own Codebase

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

Try Supermodel Free