Home / Class/ NativeDatagramPacket Class — netty Architecture

NativeDatagramPacket Class — netty Architecture

Architecture documentation for the NativeDatagramPacket class in NativeDatagramPacketArray.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  9f6481a1_7f1c_9f54_7a7a_c374e172d810["NativeDatagramPacket"]
  b2cbda6d_cb9e_3f7b_72f8_26519849d735["NativeDatagramPacketArray.java"]
  9f6481a1_7f1c_9f54_7a7a_c374e172d810 -->|defined in| b2cbda6d_cb9e_3f7b_72f8_26519849d735
  ff253642_2eb0_17f7_3ecc_98192434783f["init()"]
  9f6481a1_7f1c_9f54_7a7a_c374e172d810 -->|method| ff253642_2eb0_17f7_3ecc_98192434783f
  7eaad8bf_9cc6_493b_04fc_c75ceb5c3c6d["hasSender()"]
  9f6481a1_7f1c_9f54_7a7a_c374e172d810 -->|method| 7eaad8bf_9cc6_493b_04fc_c75ceb5c3c6d
  5f5434c6_23b1_61cc_c2e6_624f54d9572d["DatagramPacket()"]
  9f6481a1_7f1c_9f54_7a7a_c374e172d810 -->|method| 5f5434c6_23b1_61cc_c2e6_624f54d9572d

Relationship Graph

Source Code

transport-classes-epoll/src/main/java/io/netty/channel/epoll/NativeDatagramPacketArray.java lines 162–231

    @SuppressWarnings("unused")
    @UnstableApi
    public final class NativeDatagramPacket {

        // IMPORTANT: Most of the below variables are accessed via JNI. Be aware if you change any of these you also
        // need to change these in the related .c file!

        // This is the actual struct iovec*
        private long memoryAddress;
        private int count;

        private final byte[] senderAddr = new byte[16];
        private int senderAddrLen;
        private int senderScopeId;
        private int senderPort;

        private final byte[] recipientAddr = new byte[16];
        private int recipientAddrLen;
        private int recipientScopeId;
        private int recipientPort;

        private int segmentSize;

        private void init(long memoryAddress, int count, int segmentSize, InetSocketAddress recipient) {
            this.memoryAddress = memoryAddress;
            this.count = count;
            this.segmentSize = segmentSize;

            this.senderScopeId = 0;
            this.senderPort = -1;
            this.senderAddrLen = 0;

            if (recipient == null) {
                this.recipientScopeId = 0;
                this.recipientPort = 0;
                this.recipientAddrLen = 0;
            } else {
                InetAddress address = recipient.getAddress();
                if (address instanceof Inet6Address) {
                    System.arraycopy(address.getAddress(), 0, recipientAddr, 0, recipientAddr.length);
                    recipientScopeId = ((Inet6Address) address).getScopeId();
                } else {
                    copyIpv4MappedIpv6Address(address.getAddress(), recipientAddr);
                    recipientScopeId = 0;
                }
                recipientAddrLen = recipientAddr.length;
                recipientPort = recipient.getPort();
            }
        }

        boolean hasSender() {
            return senderPort >= 0;
        }

        DatagramPacket newDatagramPacket(ByteBuf buffer, InetSocketAddress recipient) throws UnknownHostException {
            InetSocketAddress sender = newAddress(senderAddr, senderAddrLen, senderPort, senderScopeId, ipv4Bytes);
            if (recipientAddrLen != 0) {
                recipient = newAddress(recipientAddr, recipientAddrLen, recipientPort, recipientScopeId, ipv4Bytes);
            }

            // Slice out the buffer with the correct length.
            ByteBuf slice = buffer.retainedSlice(buffer.readerIndex(), count);

            // UDP_GRO
            if (segmentSize > 0) {
                return new SegmentedDatagramPacket(slice, segmentSize, recipient, sender);
            }
            return new DatagramPacket(slice, recipient, sender);
        }
    }

Frequently Asked Questions

What is the NativeDatagramPacket class?
NativeDatagramPacket is a class in the netty codebase, defined in transport-classes-epoll/src/main/java/io/netty/channel/epoll/NativeDatagramPacketArray.java.
Where is NativeDatagramPacket defined?
NativeDatagramPacket is defined in transport-classes-epoll/src/main/java/io/netty/channel/epoll/NativeDatagramPacketArray.java at line 162.

Analyze Your Own Codebase

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

Try Supermodel Free