Package io.netty.channel.unix
Class IovArray
java.lang.Object
io.netty.channel.unix.IovArray
- All Implemented Interfaces:
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
FieldsModifier and TypeFieldDescriptionprivate static final int
The size of an address which should be 8 for 64 bits and 4 for 32 bits.private int
static final int
The size of aniovec
struct in bytes.private static final int
The needed memory to hold up toIOV_MAX
iov entries, whereIOV_MAX
signified the maximum number ofiovec
structs that can be passed towritev(...)
.private long
private final ByteBuf
private final long
private long
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate boolean
add
(long memoryAddress, long addr, int len) boolean
Deprecated.boolean
void
clear()
int
count()
Returns the number if iov entries.private static int
idx
(int index) long
maxBytes()
Get the maximum amount of bytes that can be added to thisIovArray
.void
maxBytes
(long maxBytes) Set the maximum amount of bytes that can be added to thisIovArray
viaadd(ByteBuf, int, int)
long
memoryAddress
(int offset) Returns thememoryAddress
for the givenoffset
.boolean
processMessage
(Object msg) Will be called for each flushed message until it either there are no more flushed messages or this method returnsfalse
.void
release()
Release theIovArray
.long
size()
Returns the size in bytes
-
Field Details
-
ADDRESS_SIZE
private static final int ADDRESS_SIZEThe size of an address which should be 8 for 64 bits and 4 for 32 bits. -
IOV_SIZE
public static final int IOV_SIZEThe size of aniovec
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_CAPACITYThe needed memory to hold up toIOV_MAX
iov entries, whereIOV_MAX
signified the maximum number ofiovec
structs that can be passed towritev(...)
. -
memoryAddress
private final long memoryAddress -
memory
-
count
private int count -
size
private long size -
maxBytes
private long maxBytes
-
-
Constructor Details
-
IovArray
public IovArray() -
IovArray
-
-
Method Details
-
clear
public void clear() -
add
Deprecated. -
add
-
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 thisIovArray
viaadd(ByteBuf, int, int)
This will not impact the existing state of the
IovArray
, and only applies to subsequent calls toadd(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 thisIovArray
.
-
maxBytes
public long maxBytes()Get the maximum amount of bytes that can be added to thisIovArray
.- Returns:
- the maximum amount of bytes that can be added to this
IovArray
.
-
memoryAddress
public long memoryAddress(int offset) Returns thememoryAddress
for the givenoffset
. -
release
public void release()Release theIovArray
. Once release further using of it may crash the JVM! -
processMessage
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 returnsfalse
.- Specified by:
processMessage
in interfaceChannelOutboundBuffer.MessageProcessor
- Throws:
Exception
-
idx
private static int idx(int index)
-
add(ByteBuf, int, int)