Home / Function/ doWrite() — netty Function Reference

doWrite() — netty Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

transport-sctp/src/main/java/io/netty/channel/sctp/oio/OioSctpChannel.java lines 239–303

    @Override
    protected void doWrite(ChannelOutboundBuffer in) throws Exception {
        if (!writeSelector.isOpen()) {
            return;
        }
        final int size = in.size();
        final int selectedKeys = writeSelector.select(SO_TIMEOUT);
        if (selectedKeys > 0) {
            final Set<SelectionKey> writableKeys = writeSelector.selectedKeys();
            if (writableKeys.isEmpty()) {
                return;
            }
            Iterator<SelectionKey> writableKeysIt = writableKeys.iterator();
            int written = 0;
            for (;;) {
                if (written == size) {
                    // all written
                    return;
                }
                writableKeysIt.next();
                writableKeysIt.remove();

                SctpMessage packet = (SctpMessage) in.current();
                if (packet == null) {
                    return;
                }

                ByteBuf data = packet.content();
                int dataLen = data.readableBytes();
                ByteBuffer nioData;

                int javaVersion = PlatformDependent.javaVersion();
                if (javaVersion >= 22 && javaVersion < 25 && data.isDirect() ||
                        !data.isDirect() || data.nioBufferCount() != 1) {
                    // Ensure that we only use a single, direct ByteBuffer when doing SCTP IO.
                    // If the ByteBuf is composite, or is on-heap, we do a copy.
                    // On Java 22 through 24, we additionally need to avoid using ByteBuffer instances that are
                    // backed by MemorySegments, because of https://bugs.openjdk.org/browse/JDK-8357268
                    if (outputCopy == null || outputCopy.capacity() < dataLen) {
                        outputCopy = ByteBuffer.allocateDirect(dataLen);
                    }
                    outputCopy.clear();
                    outputCopy.limit(dataLen);
                    data.readBytes(outputCopy);
                    outputCopy.flip();
                    nioData = outputCopy;
                } else {
                    nioData = data.nioBuffer();
                }

                final MessageInfo mi = MessageInfo.createOutgoing(association(), null, packet.streamIdentifier());
                mi.payloadProtocolID(packet.protocolIdentifier());
                mi.streamNumber(packet.streamIdentifier());
                mi.unordered(packet.isUnordered());

                ch.send(nioData, mi);
                written ++;
                in.remove();

                if (!writableKeysIt.hasNext()) {
                    return;
                }
            }
        }
    }

Domain

Subdomains

Calls

Frequently Asked Questions

What does doWrite() do?
doWrite() is a function in the netty codebase, defined in transport-sctp/src/main/java/io/netty/channel/sctp/oio/OioSctpChannel.java.
Where is doWrite() defined?
doWrite() is defined in transport-sctp/src/main/java/io/netty/channel/sctp/oio/OioSctpChannel.java at line 239.
What does doWrite() call?
doWrite() 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