From fbad073be5aa16623d6049eb47c56e1883fda579 Mon Sep 17 00:00:00 2001 From: William Hicklin Date: Wed, 3 Sep 2025 13:03:34 +0100 Subject: [PATCH] This PR updates the mqueue documentation example and adds some helpful documentation to explain the limits of the MqAttr input values. --- src/mqueue.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/mqueue.rs b/src/mqueue.rs index 7684d56858..4068f79087 100644 --- a/src/mqueue.rs +++ b/src/mqueue.rs @@ -2,24 +2,24 @@ //! //! # Example //! -// no_run because a kernel module may be required. -//! ```no_run +//! ``` //! # use std::ffi::CString; //! # use nix::mqueue::*; //! use nix::sys::stat::Mode; //! //! const MSG_SIZE: mq_attr_member_t = 32; -//! let mq_name= "/a_nix_test_queue"; +//! let attr = MqAttr::new(0, 10, MSG_SIZE, 0); +//! let mq_name= "/a_nix_doc_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 mqd0 = mq_open(mq_name, oflag0, mode, Some(&attr)).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 mqd1 = mq_open(mq_name, oflag1, mode, Some(&attr)).unwrap(); +//! let mut buf = [0u8; MSG_SIZE as usize]; //! let mut prio = 0u32; //! let len = mq_receive(&mqd1, &mut buf, &mut prio).unwrap(); //! assert_eq!(prio, 1); @@ -100,7 +100,9 @@ impl MqAttr { /// /// - `mq_flags`: Either `0` or `O_NONBLOCK`. /// - `mq_maxmsg`: Maximum number of messages on the queue. + /// The maximum value allowed by the system can be obtained from `/proc/sys/fs/mqueue/msg_max`. /// - `mq_msgsize`: Maximum message size in bytes. + /// The maximum value allowed by the system can be obtained from `/proc/sys/fs/mqueue/msgsize_max`. /// - `mq_curmsgs`: Number of messages currently in the queue. pub fn new( mq_flags: mq_attr_member_t,