Home / Class/ MsgHdr Class — netty Architecture

MsgHdr Class — netty Architecture

Architecture documentation for the MsgHdr class in MsgHdr.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  4a81f547_d99c_c526_30f9_847735bb8edf["MsgHdr"]
  ea691c5c_38f8_9079_1e3a_087678884dc3["MsgHdr.java"]
  4a81f547_d99c_c526_30f9_847735bb8edf -->|defined in| ea691c5c_38f8_9079_1e3a_087678884dc3
  d01b1b3e_5223_1a9c_695d_e756abc972b7["MsgHdr()"]
  4a81f547_d99c_c526_30f9_847735bb8edf -->|method| d01b1b3e_5223_1a9c_695d_e756abc972b7
  2945e618_b315_2c6d_4aa2_1db17ba484fe["set()"]
  4a81f547_d99c_c526_30f9_847735bb8edf -->|method| 2945e618_b315_2c6d_4aa2_1db17ba484fe
  1c0c157c_7d1a_fcb5_0464_ea2479cedb64["prepSendFd()"]
  4a81f547_d99c_c526_30f9_847735bb8edf -->|method| 1c0c157c_7d1a_fcb5_0464_ea2479cedb64
  a0f2cc56_8b05_2ba4_5adc_c5923f65761a["prepReadFd()"]
  4a81f547_d99c_c526_30f9_847735bb8edf -->|method| a0f2cc56_8b05_2ba4_5adc_c5923f65761a
  5400b655_6d57_d075_d7ea_8f014fe985b3["getCmsgData()"]
  4a81f547_d99c_c526_30f9_847735bb8edf -->|method| 5400b655_6d57_d075_d7ea_8f014fe985b3

Relationship Graph

Source Code

transport-classes-io_uring/src/main/java/io/netty/channel/uring/MsgHdr.java lines 35–132

final class MsgHdr {

    private MsgHdr() { }

    static void set(ByteBuffer memory, long iovMemory, int iovLength) {
        int memoryPosition = memory.position();
        memory.putInt(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_NAMELEN, 0);
        if (Native.SIZEOF_SIZE_T == 4) {
            memory.putInt(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_NAME, 0);
            memory.putInt(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_IOV, (int) iovMemory);
            memory.putInt(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_IOVLEN, iovLength);
            memory.putInt(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_CONTROL, 0);
            memory.putInt(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_CONTROLLEN, 0);
        } else {
            assert Native.SIZEOF_SIZE_T == 8;
            memory.putLong(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_NAME, 0);
            memory.putLong(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_IOV, iovMemory);
            memory.putLong(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_IOVLEN, iovLength);
            memory.putLong(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_CONTROL, 0);
            memory.putLong(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_CONTROLLEN, 0);
        }
    }

    static void set(ByteBuffer memory, ByteBuffer sockAddrMemory, int addressSize, ByteBuffer iovMemory, int iovLength,
                    ByteBuffer msgControl, int cmsgHdrDataOffset, short segmentSize) {
        int memoryPosition = memory.position();
        memory.putInt(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_NAMELEN, addressSize);

        int msgControlLen = 0;
        long msgControlAddr;
        if (segmentSize > 0 && msgControl != null && cmsgHdrDataOffset >= 0) {
            msgControlLen = Native.CMSG_LEN;
            CmsgHdr.write(msgControl, cmsgHdrDataOffset, Native.CMSG_LEN, Native.SOL_UDP,
                    Native.UDP_SEGMENT, segmentSize);
            msgControlAddr = Buffer.memoryAddress(msgControl) + msgControl.position();
        } else {
            // Set to 0 if we not explicit requested GSO.
            msgControlAddr = 0;
        }
        long sockAddr = sockAddrMemory == null ? 0 : Buffer.memoryAddress(sockAddrMemory);
        if (Native.SIZEOF_SIZE_T == 4) {
            memory.putInt(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_NAME, (int) sockAddr);
            memory.putInt(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_IOV, (int) Buffer.memoryAddress(iovMemory));
            memory.putInt(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_IOVLEN, iovLength);
            memory.putInt(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_CONTROL, (int) msgControlAddr);
            memory.putInt(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_CONTROLLEN, msgControlLen);
        } else {
            assert Native.SIZEOF_SIZE_T == 8;
            memory.putLong(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_NAME, sockAddr);
            memory.putLong(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_IOV, Buffer.memoryAddress(iovMemory));
            memory.putLong(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_IOVLEN, iovLength);
            memory.putLong(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_CONTROL, msgControlAddr);
            memory.putLong(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_CONTROLLEN, msgControlLen);
        }
        // No flags (we assume the memory was memset before)
    }

    static void prepSendFd(ByteBuffer memory, int fd, ByteBuffer msgControl,
                           int cmsgHdrDataOffset, ByteBuffer iovMemory, int iovLength) {
        int memoryPosition = memory.position();
        long msgControlAddr = Buffer.memoryAddress(msgControl);
        CmsgHdr.writeScmRights(msgControl, cmsgHdrDataOffset, fd);
        if (Native.SIZEOF_SIZE_T == 4) {
            memory.putInt(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_CONTROL, (int) msgControlAddr);
            memory.putInt(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_CONTROLLEN, Native.MSG_CONTROL_LEN_FOR_FD);
            memory.putInt(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_IOV, (int) Buffer.memoryAddress(iovMemory));
            memory.putInt(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_IOVLEN, iovLength);
        } else {
            assert Native.SIZEOF_SIZE_T == 8;
            memory.putLong(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_CONTROL, msgControlAddr);
            memory.putLong(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_CONTROLLEN, Native.MSG_CONTROL_LEN_FOR_FD);
            memory.putLong(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_IOV, Buffer.memoryAddress(iovMemory));
            memory.putLong(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_IOVLEN, iovLength);
        }
    }

    static void prepReadFd(ByteBuffer memory, ByteBuffer msgControl, int cmsgHdrDataOffset,
                           ByteBuffer iovMemory, int iovLength) {
        int memoryPosition = memory.position();
        long msgControlAddr = Buffer.memoryAddress(msgControl);
        if (Native.SIZEOF_SIZE_T == 4) {

Frequently Asked Questions

What is the MsgHdr class?
MsgHdr is a class in the netty codebase, defined in transport-classes-io_uring/src/main/java/io/netty/channel/uring/MsgHdr.java.
Where is MsgHdr defined?
MsgHdr is defined in transport-classes-io_uring/src/main/java/io/netty/channel/uring/MsgHdr.java at line 35.

Analyze Your Own Codebase

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

Try Supermodel Free