Home / Function/ doReadMessages() — netty Function Reference

doReadMessages() — netty Function Reference

Architecture documentation for the doReadMessages() function in OioSctpChannel.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  29800e14_3a2a_9b5f_2cf5_0cb009d693b6["doReadMessages()"]
  0e982d34_5d94_834c_1668_451f9d08d74b["OioSctpChannel"]
  29800e14_3a2a_9b5f_2cf5_0cb009d693b6 -->|defined in| 0e982d34_5d94_834c_1668_451f9d08d74b
  89375452_19bd_181e_bf20_006d404d30b8["isOpen()"]
  29800e14_3a2a_9b5f_2cf5_0cb009d693b6 -->|calls| 89375452_19bd_181e_bf20_006d404d30b8
  style 29800e14_3a2a_9b5f_2cf5_0cb009d693b6 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

transport-sctp/src/main/java/io/netty/channel/sctp/oio/OioSctpChannel.java lines 176–237

    @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;
        }
        // We must clear the selectedKeys because the Selector will never do it. If we do not clear it, the selectionKey
        // will always be returned even if there is no data can be read which causes performance issue. And in some
        // implementation of Selector, the select method may return 0 if the selectionKey which is ready for process has
        // already been in the selectedKeys and cause the keysSelected above to be false even if we actually have
        // something to read.
        readSelector.selectedKeys().clear();
        final RecvByteBufAllocator.Handle allocHandle = unsafe().recvBufAllocHandle();
        ByteBuf buffer = allocHandle.allocate(config().getAllocator());
        boolean free = true;

        try {
            ByteBuffer data = buffer.nioBuffer(buffer.writerIndex(), buffer.writableBytes());
            boolean useInputCopy = false;
            int javaVersion = PlatformDependent.javaVersion();
            if (javaVersion >= 22 && javaVersion < 25 && data.isDirect()) {
                // On Java 22 through 24, we need to avoid using ByteBuffer instances that are
                // backed by MemorySegments, because of https://bugs.openjdk.org/browse/JDK-8357268
                if (inputCopy == null || inputCopy.capacity() < data.remaining()) {
                    inputCopy = ByteBuffer.allocateDirect(data.remaining());
                }
                inputCopy.clear();
                inputCopy.limit(data.remaining());
                useInputCopy = true;
            }
            MessageInfo messageInfo = ch.receive(useInputCopy ? inputCopy : data, null, notificationHandler);
            if (messageInfo == null) {
                return readMessages;
            }
            if (useInputCopy) {
                inputCopy.flip();
                data.put(inputCopy);
            }

            data.flip();
            allocHandle.lastBytesRead(data.remaining());
            msgs.add(new SctpMessage(messageInfo,
                    buffer.writerIndex(buffer.writerIndex() + allocHandle.lastBytesRead())));
            free = false;
            ++readMessages;
        } catch (Throwable cause) {
            PlatformDependent.throwException(cause);
        }  finally {
            if (free) {
                buffer.release();
            }
        }
        return readMessages;
    }

Domain

Subdomains

Calls

Frequently Asked Questions

What does doReadMessages() do?
doReadMessages() is a function in the netty codebase, defined in transport-sctp/src/main/java/io/netty/channel/sctp/oio/OioSctpChannel.java.
Where is doReadMessages() defined?
doReadMessages() is defined in transport-sctp/src/main/java/io/netty/channel/sctp/oio/OioSctpChannel.java at line 176.
What does doReadMessages() call?
doReadMessages() calls 1 function(s): isOpen.

Analyze Your Own Codebase

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

Try Supermodel Free