Home / Function/ doReadMessages() — netty Function Reference

doReadMessages() — netty Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  dc7ae298_8072_0d75_7357_53b6db7309d4["doReadMessages()"]
  ce6c049a_7822_1e77_29fc_0d83a1e2ef54["NioSctpChannel"]
  dc7ae298_8072_0d75_7357_53b6db7309d4 -->|defined in| ce6c049a_7822_1e77_29fc_0d83a1e2ef54
  style dc7ae298_8072_0d75_7357_53b6db7309d4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

transport-sctp/src/main/java/io/netty/channel/sctp/nio/NioSctpChannel.java lines 264–309

    @Override
    protected int doReadMessages(List<Object> buf) throws Exception {
        SctpChannel ch = javaChannel();

        RecvByteBufAllocator.Handle allocHandle = unsafe().recvBufAllocHandle();
        ByteBuf buffer = allocHandle.allocate(config().getAllocator());
        boolean free = true;
        try {
            ByteBuffer data = buffer.internalNioBuffer(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;
            }
            int pos = data.position();

            MessageInfo messageInfo = ch.receive(useInputCopy ? inputCopy : data, null, notificationHandler);
            if (messageInfo == null) {
                return 0;
            }
            if (useInputCopy) {
                inputCopy.flip();
                data.put(inputCopy);
            }

            allocHandle.lastBytesRead(data.position() - pos);
            buf.add(new SctpMessage(messageInfo,
                    buffer.writerIndex(buffer.writerIndex() + allocHandle.lastBytesRead())));
            free = false;
            return 1;
        } catch (Throwable cause) {
            PlatformDependent.throwException(cause);
            return -1;
        }  finally {
            if (free) {
                buffer.release();
            }
        }
    }

Domain

Subdomains

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/nio/NioSctpChannel.java.
Where is doReadMessages() defined?
doReadMessages() is defined in transport-sctp/src/main/java/io/netty/channel/sctp/nio/NioSctpChannel.java at line 264.

Analyze Your Own Codebase

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

Try Supermodel Free