Skip to content

Commit fbad073

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 fbad073

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/mqueue.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@
22
//!
33
//! # Example
44
//!
5-
// no_run because a kernel module may be required.
6-
//! ```no_run
5+
//! ```
76
//! # use std::ffi::CString;
87
//! # use nix::mqueue::*;
98
//! use nix::sys::stat::Mode;
109
//!
1110
//! const MSG_SIZE: mq_attr_member_t = 32;
12-
//! let mq_name= "/a_nix_test_queue";
11+
//! let attr = MqAttr::new(0, 10, MSG_SIZE, 0);
12+
//! let mq_name= "/a_nix_doc_test_queue";
1313
//!
1414
//! let oflag0 = MQ_OFlag::O_CREAT | MQ_OFlag::O_WRONLY;
1515
//! 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();
16+
//! let mqd0 = mq_open(mq_name, oflag0, mode, Some(&attr)).unwrap();
1717
//! let msg_to_send = b"msg_1";
1818
//! mq_send(&mqd0, msg_to_send, 1).unwrap();
1919
//!
2020
//! 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];
21+
//! let mqd1 = mq_open(mq_name, oflag1, mode, Some(&attr)).unwrap();
22+
//! let mut buf = [0u8; MSG_SIZE as usize];
2323
//! let mut prio = 0u32;
2424
//! let len = mq_receive(&mqd1, &mut buf, &mut prio).unwrap();
2525
//! assert_eq!(prio, 1);
@@ -100,7 +100,9 @@ impl MqAttr {
100100
///
101101
/// - `mq_flags`: Either `0` or `O_NONBLOCK`.
102102
/// - `mq_maxmsg`: Maximum number of messages on the queue.
103+
/// The maximum value allowed by the system can be obtained from `/proc/sys/fs/mqueue/msg_max`.
103104
/// - `mq_msgsize`: Maximum message size in bytes.
105+
/// The maximum value allowed by the system can be obtained from `/proc/sys/fs/mqueue/msgsize_max`.
104106
/// - `mq_curmsgs`: Number of messages currently in the queue.
105107
pub fn new(
106108
mq_flags: mq_attr_member_t,

0 commit comments

Comments
 (0)