Module mqueue

Source
Available on crate feature mqueue only.
Expand description

Posix Message Queue functions

§Example

use nix::sys::stat::Mode;

const MSG_SIZE: mq_attr_member_t = 32;
let mq_name= "/a_nix_test_queue";

let oflag0 = MQ_OFlag::O_CREAT | MQ_OFlag::O_WRONLY;
let mode = Mode::S_IWUSR | Mode::S_IRUSR | Mode::S_IRGRP | Mode::S_IROTH;
let mqd0 = mq_open(mq_name, oflag0, mode, None).unwrap();
let msg_to_send = b"msg_1";
mq_send(&mqd0, msg_to_send, 1).unwrap();

let oflag1 = MQ_OFlag::O_CREAT | MQ_OFlag::O_RDONLY;
let mqd1 = mq_open(mq_name, oflag1, mode, None).unwrap();
let mut buf = [0u8; 32];
let mut prio = 0u32;
let len = mq_receive(&mqd1, &mut buf, &mut prio).unwrap();
assert_eq!(prio, 1);
assert_eq!(msg_to_send, &buf[0..len]);

mq_close(mqd1).unwrap();
mq_close(mqd0).unwrap();

Further reading and details on the C API

Structs§

MQ_OFlag
Used with mq_open.
MqAttr
A message-queue attribute, optionally used with mq_setattr and mq_getattr and optionally mq_open,
MqdT
Identifies an open POSIX Message Queue

Functions§

mq_close
Close a message queue
mq_getattr
Get message queue attributes
mq_open
Open a message queue
mq_receive
Receive a message from a message queue
mq_remove_nonblock
Convenience function. Removes O_NONBLOCK attribute for a given message queue descriptor Returns the old attributes
mq_send
Send a message to a message queue
mq_set_nonblock
Convenience function. Sets the O_NONBLOCK attribute for a given message queue descriptor Returns the old attributes
mq_setattr
Set the attributes of the message queue. Only O_NONBLOCK can be set, everything else will be ignored. Returns the old attributes.
mq_timedreceivetime
Receive a message from a message queue with a timeout
mq_unlink
Remove a message queue

Type Aliases§

mq_attr_member_t
Size of a message queue attribute member