Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/mqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,14 @@ where
&mq_attr.mq_attr as *const libc::mq_attr,
)
},
None => unsafe { libc::mq_open(cstr.as_ptr(), oflag.bits()) },
None => unsafe {
libc::mq_open(
cstr.as_ptr(),
oflag.bits(),
mode.bits() as libc::c_int,
::std::ptr::null() as *const libc::mq_attr,
)
},
})?;

Errno::result(res).map(MqdT)
Expand Down
27 changes: 27 additions & 0 deletions test/test_mq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,33 @@ fn test_mq_send_and_receive() {
assert_eq!(msg_to_send, str::from_utf8(&buf[0..len]).unwrap());
}

#[test]
fn test_mq_send_and_receive_noattr() {
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 r0 = mq_open(mq_name, oflag0, mode, None);
if let Err(Errno::ENOSYS) = r0 {
println!("message queues not supported or module not loaded?");
return;
};
let mqd0 = r0.unwrap();
let msg_to_send = "msg_1";
mq_send(&mqd0, msg_to_send.as_bytes(), 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);

mq_close(mqd1).unwrap();
mq_close(mqd0).unwrap();
assert_eq!(msg_to_send, str::from_utf8(&buf[0..len]).unwrap());
}

#[test]
fn test_mq_timedreceive() {
const MSG_SIZE: mq_attr_member_t = 32;
Expand Down
Loading