- java.lang.Object
-
- io.netty5.channel.unix.IovArray
-
- All Implemented Interfaces:
ReadableComponentProcessor<RuntimeException>
,WritableComponentProcessor<RuntimeException>
,ChannelOutboundBuffer.MessageProcessor
public final class IovArray extends Object implements ChannelOutboundBuffer.MessageProcessor, ReadableComponentProcessor<RuntimeException>, WritableComponentProcessor<RuntimeException>
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 alsoman 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 static int
IOV_SIZE
The size of aniovec
struct in bytes.
-
Constructor Summary
Constructors Constructor Description IovArray()
IovArray(ByteBuffer memory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
int
count()
Returns the number if iov entries.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(long, long, int)
orprocessMessage(Object)
.long
memoryAddress(int index)
Returns thememoryAddress
for the givenindex
.boolean
process(int index, ReadableComponent component)
Process the given component at the given index in theiteration
.boolean
process(int index, WritableComponent component)
Process the given component at the given index in theBuffer.forEachWritable(int, WritableComponentProcessor)
iteration}.boolean
process(ReadableComponent component, int byteCount)
boolean
process(WritableComponent component, int byteCount)
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
-
-
-
Constructor Detail
-
IovArray
public IovArray()
-
IovArray
public IovArray(ByteBuffer memory)
-
-
Method Detail
-
clear
public void clear()
-
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(long, long, int)
orprocessMessage(Object)
.This will not impact the existing state of the
IovArray
, and only applies to subsequent calls toadd(long, long, int)
orprocessMessage(Object)
.In order to ensure some progress is made at least one
Buffer
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 index)
Returns thememoryAddress
for the givenindex
.
-
release
public void release()
Release theIovArray
. Once release further using of it may crash the JVM!
-
processMessage
public boolean processMessage(Object msg)
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
-
process
public boolean process(int index, ReadableComponent component)
Description copied from interface:ReadableComponentProcessor
Process the given component at the given index in theiteration
.The component object itself is only valid during this call, but the
byte buffers
, arrays, and native address pointers obtained from it, will be valid until any operation is performed on the buffer, which changes the internal memory.- Specified by:
process
in interfaceReadableComponentProcessor<RuntimeException>
- Parameters:
index
- The current index of the given buffer component, based on the initial index passed to theBuffer.forEachReadable(int, ReadableComponentProcessor)
method.component
- The current buffer component being processed.- Returns:
true
if the iteration should continue and more components should be processed, otherwisefalse
to stop the iteration early.
-
process
public boolean process(ReadableComponent component, int byteCount)
-
process
public boolean process(int index, WritableComponent component)
Description copied from interface:WritableComponentProcessor
Process the given component at the given index in theBuffer.forEachWritable(int, WritableComponentProcessor)
iteration}.The component object itself is only valid during this call, but the
byte buffers
, arrays, and native address pointers obtained from it, will be valid until anyownership
requiring operation is performed on the buffer.- Specified by:
process
in interfaceWritableComponentProcessor<RuntimeException>
- Parameters:
index
- The current index of the given buffer component, based on the initial index passed to theBuffer.forEachWritable(int, WritableComponentProcessor)
method.component
- The current buffer component being processed.- Returns:
true
if the iteration should continue and more components should be processed, otherwisefalse
to stop the iteration early.
-
process
public boolean process(WritableComponent component, int byteCount)
-
-