Home / Class/ IovArray Class — netty Architecture

IovArray Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  472075eb_7f6c_c7dd_f847_0a44a55d5687["IovArray"]
  5adf7da4_2c5f_c14d_4e86_8ab9a8ebd368["IovArray.java"]
  472075eb_7f6c_c7dd_f847_0a44a55d5687 -->|defined in| 5adf7da4_2c5f_c14d_4e86_8ab9a8ebd368
  dbbdf2bf_9857_67f1_feae_8c9b81bc4bcd["IovArray()"]
  472075eb_7f6c_c7dd_f847_0a44a55d5687 -->|method| dbbdf2bf_9857_67f1_feae_8c9b81bc4bcd
  6383c644_d18d_eaca_2709_d5daec24f087["clear()"]
  472075eb_7f6c_c7dd_f847_0a44a55d5687 -->|method| 6383c644_d18d_eaca_2709_d5daec24f087
  eccf2b30_f29c_ec2c_92e1_8fb71691212d["add()"]
  472075eb_7f6c_c7dd_f847_0a44a55d5687 -->|method| eccf2b30_f29c_ec2c_92e1_8fb71691212d
  afe658fa_2fd0_f743_3adf_251941e62070["isFull()"]
  472075eb_7f6c_c7dd_f847_0a44a55d5687 -->|method| afe658fa_2fd0_f743_3adf_251941e62070
  2197be93_dcfc_cf53_3502_886fb2d86e43["count()"]
  472075eb_7f6c_c7dd_f847_0a44a55d5687 -->|method| 2197be93_dcfc_cf53_3502_886fb2d86e43
  810a2d2c_8d92_3f7d_db96_9ec8dbcfbbe5["size()"]
  472075eb_7f6c_c7dd_f847_0a44a55d5687 -->|method| 810a2d2c_8d92_3f7d_db96_9ec8dbcfbbe5
  41e89c43_c26e_2674_f71c_7fe5cc3191f9["maxBytes()"]
  472075eb_7f6c_c7dd_f847_0a44a55d5687 -->|method| 41e89c43_c26e_2674_f71c_7fe5cc3191f9
  435c86ff_a592_c234_1832_7aab2926cc13["maxCount()"]
  472075eb_7f6c_c7dd_f847_0a44a55d5687 -->|method| 435c86ff_a592_c234_1832_7aab2926cc13
  d37b3634_64af_1ccc_fc8c_413fe29ae253["memoryAddress()"]
  472075eb_7f6c_c7dd_f847_0a44a55d5687 -->|method| d37b3634_64af_1ccc_fc8c_413fe29ae253
  01a466e8_64b4_902d_6ca9_31fba0c43e51["release()"]
  472075eb_7f6c_c7dd_f847_0a44a55d5687 -->|method| 01a466e8_64b4_902d_6ca9_31fba0c43e51
  ab225a97_7d56_d559_59b5_32532eb669ae["processMessage()"]
  472075eb_7f6c_c7dd_f847_0a44a55d5687 -->|method| ab225a97_7d56_d559_59b5_32532eb669ae
  021c1330_3aad_024d_251d_443291002f12["idx()"]
  472075eb_7f6c_c7dd_f847_0a44a55d5687 -->|method| 021c1330_3aad_024d_251d_443291002f12

Relationship Graph

Source Code

transport-native-unix-common/src/main/java/io/netty/channel/unix/IovArray.java lines 49–314

public final class IovArray implements MessageProcessor {

    /** The size of an address which should be 8 for 64 bits and 4 for 32 bits. */
    private static final int ADDRESS_SIZE = Buffer.addressSize();

    /**
     * The size of an {@code iovec} struct in bytes. This is calculated as we have 2 entries each of the size of the
     * address.
     */
    public static final int IOV_SIZE = 2 * ADDRESS_SIZE;

    /**
     * The needed memory to hold up to {@code IOV_MAX} iov entries, where {@code IOV_MAX} signified
     * the maximum number of {@code iovec} structs that can be passed to {@code writev(...)}.
     */
    private static final int MAX_CAPACITY = IOV_MAX * IOV_SIZE;

    private final long memoryAddress;
    private final ByteBuf memory;
    private final CleanableDirectBuffer cleanable;
    private int count;
    private long size;
    private long maxBytes = SSIZE_MAX;
    private int maxCount;

    /**
     * @deprecated Use {@link #IovArray(int)} instead.
     */
    @Deprecated
    public IovArray() {
        this(IOV_MAX);
    }

    /**
     * Allocate an IovArray with enough room for the given number of <strong>entries</strong> (not bytes).
     * @param numEntries The desired number of entries in the IovArray.
     */
    @SuppressWarnings("deprecation")
    public IovArray(int numEntries) {
        int sizeBytes = Math.multiplyExact(checkPositive(numEntries, "numEntries"), IOV_SIZE);
        cleanable = Buffer.allocateDirectBufferWithNativeOrder(sizeBytes);
        ByteBuf bbuf = Unpooled.wrappedBuffer(cleanable.buffer()).setIndex(0, 0);
        memory = PlatformDependent.hasUnsafe() ? bbuf : bbuf.order(
                PlatformDependent.BIG_ENDIAN_NATIVE_ORDER ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
        if (memory.hasMemoryAddress()) {
            memoryAddress = memory.memoryAddress();
        } else {
            // Fallback to using JNI as we were not be able to access the address otherwise.

            // Use internalNioBuffer to reduce object creation.
            // It is important to add the position as the returned ByteBuffer might be shared by multiple ByteBuf
            // instances and so has an address that starts before the start of the ByteBuf itself.
            ByteBuffer byteBuffer = memory.internalNioBuffer(0, memory.capacity());
            memoryAddress = Buffer.memoryAddress(byteBuffer) + byteBuffer.position();
        }
        maxCount = IOV_MAX;
    }

    /**
     * @param memory The underlying memory.
     * @deprecated Use {@link #IovArray(int)} instead.
     */
    @Deprecated
    public IovArray(ByteBuf memory) {
        assert memory.writerIndex() == 0;
        assert memory.readerIndex() == 0;
        this.memory = PlatformDependent.hasUnsafe() ? memory : memory.order(
                PlatformDependent.BIG_ENDIAN_NATIVE_ORDER ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
        if (memory.hasMemoryAddress()) {
            memoryAddress = memory.memoryAddress();
        } else {
            // Fallback to using JNI as we were not be able to access the address otherwise.

            // Use internalNioBuffer to reduce object creation.
            // It is important to add the position as the returned ByteBuffer might be shared by multiple ByteBuf
            // instances and so has an address that starts before the start of the ByteBuf itself.
            ByteBuffer byteBuffer = memory.internalNioBuffer(0, memory.capacity());
            memoryAddress = Buffer.memoryAddress(byteBuffer) + byteBuffer.position();
        }
        cleanable = null;
        maxCount = IOV_MAX;

Frequently Asked Questions

What is the IovArray class?
IovArray is a class in the netty codebase, defined in transport-native-unix-common/src/main/java/io/netty/channel/unix/IovArray.java.
Where is IovArray defined?
IovArray is defined in transport-native-unix-common/src/main/java/io/netty/channel/unix/IovArray.java at line 49.

Analyze Your Own Codebase

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

Try Supermodel Free