Module nix::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§

Functions§

  • Close a message queue
  • Get message queue attributes
  • Open a message queue
  • Receive a message from a message queue
  • Convenience function. Removes O_NONBLOCK attribute for a given message queue descriptor Returns the old attributes
  • Send a message to a message queue
  • Convenience function. Sets the O_NONBLOCK attribute for a given message queue descriptor Returns the old attributes
  • Set the attributes of the message queue. Only O_NONBLOCK can be set, everything else will be ignored Returns the old attributes It is recommend to use the mq_set_nonblock() and mq_remove_nonblock() convenience functions as they are easier to use
  • Receive a message from a message queue with a timeout
  • Remove a message queue

Type Aliases§