Class IovArray

java.lang.Object
io.netty.channel.unix.IovArray
All Implemented Interfaces:
ChannelOutboundBuffer.MessageProcessor

public final class IovArray extends java.lang.Object implements ChannelOutboundBuffer.MessageProcessor
Represent an array of struct array and so can be passed directly over via JNI without the need to do any more array copies. The buffers are written out directly into direct memory to match the struct iov. See also man writev.
struct iovec {
  void  *iov_base;
  size_t iov_len;
};
See also Efficient JNI programming IV: Wrapping native data objects.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final int
    The size of an address which should be 8 for 64 bits and 4 for 32 bits.
    private final CleanableDirectBuffer
     
    private int
     
    static final int
    The size of an iovec struct in bytes.
    private static final int
    The needed memory to hold up to IOV_MAX iov entries, where IOV_MAX signified the maximum number of iovec structs that can be passed to writev(...).
    private long
     
    private int
     
    private final ByteBuf
     
    private final long
     
    private long
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Deprecated.
    Use IovArray(int) instead.
    IovArray(int numEntries)
    Allocate an IovArray with enough room for the given number of entries (not bytes).
    IovArray(ByteBuf memory)
    Deprecated.
    Use IovArray(int) instead.
  • Method Summary

    Modifier and Type
    Method
    Description
    private boolean
    add(long memoryAddress, long addr, int len)
     
    boolean
    add(ByteBuf buf)
    Deprecated.
    boolean
    add(ByteBuf buf, int offset, int len)
     
    void
     
    int
    Returns the number if iov entries.
    private static int
    idx(int index)
     
    boolean
    Return true if there is no more space left in the IovArray.
    long
    Get the maximum amount of bytes that can be added to this IovArray.
    void
    maxBytes(long maxBytes)
    Set the maximum amount of bytes that can be added to this IovArray via add(ByteBuf, int, int)
    int
    Get the maximum amount of buffers that can be added to this IovArray.
    void
    maxCount(int maxCount)
    Set the maximum amount of buffers that can be added to this IovArray via add(ByteBuf, int, int)
    long
    memoryAddress(int offset)
    Returns the memoryAddress for the given offset.
    boolean
    processMessage(java.lang.Object msg)
    Will be called for each flushed message until it either there are no more flushed messages or this method returns false.
    void
    Release the IovArray.
    long
    Returns the size in bytes

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ADDRESS_SIZE

      private static final int ADDRESS_SIZE
      The size of an address which should be 8 for 64 bits and 4 for 32 bits.
    • IOV_SIZE

      public static final int IOV_SIZE
      The size of an iovec struct in bytes. This is calculated as we have 2 entries each of the size of the address.
    • MAX_CAPACITY

      private static final int MAX_CAPACITY
      The needed memory to hold up to IOV_MAX iov entries, where IOV_MAX signified the maximum number of iovec structs that can be passed to writev(...).
    • memoryAddress

      private final long memoryAddress
    • memory

      private final ByteBuf memory
    • cleanable

      private final CleanableDirectBuffer cleanable
    • count

      private int count
    • size

      private long size
    • maxBytes

      private long maxBytes
    • maxCount

      private int maxCount
  • Constructor Details

    • IovArray

      @Deprecated public IovArray()
      Deprecated.
      Use IovArray(int) instead.
    • IovArray

      public IovArray(int numEntries)
      Allocate an IovArray with enough room for the given number of entries (not bytes).
      Parameters:
      numEntries - The desired number of entries in the IovArray.
    • IovArray

      @Deprecated public IovArray(ByteBuf memory)
      Deprecated.
      Use IovArray(int) instead.
      Parameters:
      memory - The underlying memory.
  • Method Details

    • clear

      public void clear()
    • add

      @Deprecated public boolean add(ByteBuf buf)
      Deprecated.
    • add

      public boolean add(ByteBuf buf, int offset, int len)
    • isFull

      public boolean isFull()
      Return true if there is no more space left in the IovArray.
      Returns:
      full or not.
    • add

      private boolean add(long memoryAddress, long addr, int len)
    • count

      public int count()
      Returns the number if iov entries.
    • size

      public long size()
      Returns the size in bytes
    • maxBytes

      public void maxBytes(long maxBytes)
      Set the maximum amount of bytes that can be added to this IovArray via add(ByteBuf, int, int)

      This will not impact the existing state of the IovArray, and only applies to subsequent calls to add(ByteBuf).

      In order to ensure some progress is made at least one ByteBuf will be accepted even if it's size exceeds this value.

      Parameters:
      maxBytes - the maximum amount of bytes that can be added to this IovArray.
    • maxCount

      public void maxCount(int maxCount)
      Set the maximum amount of buffers that can be added to this IovArray via add(ByteBuf, int, int)

      This will not impact the existing state of the IovArray, and only applies to subsequent calls to add(ByteBuf).

      Parameters:
      maxCount - the maximum amount of bytes that can be added to this IovArray.
    • maxBytes

      public long maxBytes()
      Get the maximum amount of bytes that can be added to this IovArray.
      Returns:
      the maximum amount of bytes that can be added to this IovArray.
    • maxCount

      public int maxCount()
      Get the maximum amount of buffers that can be added to this IovArray.
      Returns:
      the maximum amount of buffers that can be added to this IovArray.
    • memoryAddress

      public long memoryAddress(int offset)
      Returns the memoryAddress for the given offset.
    • release

      public void release()
      Release the IovArray. Once release further using of it may crash the JVM!
    • processMessage

      public boolean processMessage(java.lang.Object msg) throws java.lang.Exception
      Description copied from interface: ChannelOutboundBuffer.MessageProcessor
      Will be called for each flushed message until it either there are no more flushed messages or this method returns false.
      Specified by:
      processMessage in interface ChannelOutboundBuffer.MessageProcessor
      Throws:
      java.lang.Exception
    • idx

      private static int idx(int index)