Skip to content

Commit 63b5c13

Browse files
committed
This PR updates the mqueue documentation example and adds some helpful documentation to explain the limits of the MqAttr input values.
1 parent 09d66fe commit 63b5c13

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/mqueue.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,18 @@
99
//! use nix::sys::stat::Mode;
1010
//!
1111
//! const MSG_SIZE: mq_attr_member_t = 32;
12-
//! let mq_name= "/a_nix_test_queue";
12+
//! let attr = MqAttr::new(0, 10, MSG_SIZE, 0);
13+
//! let mq_name= "/a_nix_doc_test_queue";
1314
//!
1415
//! let oflag0 = MQ_OFlag::O_CREAT | MQ_OFlag::O_WRONLY;
1516
//! let mode = Mode::S_IWUSR | Mode::S_IRUSR | Mode::S_IRGRP | Mode::S_IROTH;
16-
//! let mqd0 = mq_open(mq_name, oflag0, mode, None).unwrap();
17+
//! let mqd0 = mq_open(mq_name, oflag0, mode, Some(&attr)).unwrap();
1718
//! let msg_to_send = b"msg_1";
1819
//! mq_send(&mqd0, msg_to_send, 1).unwrap();
1920
//!
2021
//! let oflag1 = MQ_OFlag::O_CREAT | MQ_OFlag::O_RDONLY;
21-
//! let mqd1 = mq_open(mq_name, oflag1, mode, None).unwrap();
22-
//! let mut buf = [0u8; 32];
22+
//! let mqd1 = mq_open(mq_name, oflag1, mode, Some(&attr)).unwrap();
23+
//! let mut buf = [0u8; MSG_SIZE as usize];
2324
//! let mut prio = 0u32;
2425
//! let len = mq_receive(&mqd1, &mut buf, &mut prio).unwrap();
2526
//! assert_eq!(prio, 1);
@@ -100,7 +101,9 @@ impl MqAttr {
100101
///
101102
/// - `mq_flags`: Either `0` or `O_NONBLOCK`.
102103
/// - `mq_maxmsg`: Maximum number of messages on the queue.
104+
/// The maximum value allowed by the system can be obtained from `/proc/sys/fs/mqueue/msg_max`.
103105
/// - `mq_msgsize`: Maximum message size in bytes.
106+
/// The maximum value allowed by the system can be obtained from `/proc/sys/fs/mqueue/msgsize_max`.
104107
/// - `mq_curmsgs`: Number of messages currently in the queue.
105108
pub fn new(
106109
mq_flags: mq_attr_member_t,

0 commit comments

Comments
 (0)