#[repr(C)]pub struct Message {
pub mtype: i64,
pub mtext: [u8; 65536],
}
Expand description
This struct represents a message that is inserted into
a message queue on every MessageQueue::send()
call.
It follows the SysV message recipe of having only two fields, namely:
mtype: i64
- which is the type of a message, it can be used for filtering within queues and should never be a negative integer. u64 isn’t used here, however, because of the kernel’s anticipated internal representationmtext
- which is where the data of the message are stored. The kernel doesn’t care about whatmtext
is so long as it is not a pointer (because pointers are a recipe for trouble when passing the interprocess boundary). Therefore it can be either a struct or an array. Here, an array of 8K bytes was chosen to allow the maximum versatility within the default message size limit (8KiB). In the future, functionality to affect the limit shall be exposed and bigger messages will be allowed
Messages are required to be #[repr(C)] to avoid unexpected surprises.
Finally, due to the size of a Message, it is unwise to store them on the stack. On Arch x86_64, the default stack size is 8mb, which is just enough for less than a thousand messages. Use Box instead.
Fields§
§mtype: i64
This should be a positive integer. For normal usage, it is inconsequential, but you may want to use it for filtering.
In fact, if you are looking for messages
with a specific type, the msgtyp
parameter
of msgrcv()
might be of use to you.
Check out its documentation for more info.
mtext: [u8; 65536]
This is a simple byte array. The ‘standard’
allows for mtext to be either a structure
or an array. For the purposes of ipc-rs
,
array is the better choice.
Currently, the data is stored as CBOR, the
more efficient byte JSON. Check out the
documentation of serde_cbor
.