summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mqueue.rs7
-rw-r--r--test/test_mq.rs30
2 files changed, 32 insertions, 5 deletions
diff --git a/src/mqueue.rs b/src/mqueue.rs
index ee2e5f2d..d225465b 100644
--- a/src/mqueue.rs
+++ b/src/mqueue.rs
@@ -42,6 +42,8 @@ mod ffi {
pub fn mq_close (mqd: MQd) -> c_int;
+ pub fn mq_unlink(name: *const c_char) -> c_int;
+
pub fn mq_receive (mqd: MQd, msg_ptr: *const c_char, msg_len: size_t, msq_prio: *const c_uint) -> ssize_t;
pub fn mq_send (mqd: MQd, msg_ptr: *const c_char, msg_len: size_t, msq_prio: c_uint) -> c_int;
@@ -78,6 +80,11 @@ pub fn mq_open(name: &CString, oflag: MQ_OFlag, mode: Mode, attr: &MqAttr) -> Re
Ok(res)
}
+pub fn mq_unlink(name: &CString) -> Result<()> {
+ let res = unsafe { ffi::mq_unlink(name.as_ptr()) };
+ from_ffi(res)
+}
+
pub fn mq_close(mqdes: MQd) -> Result<()> {
let res = unsafe { ffi::mq_close(mqdes) };
from_ffi(res)
diff --git a/test/test_mq.rs b/test/test_mq.rs
index 7821ba51..ecd6e5b9 100644
--- a/test/test_mq.rs
+++ b/test/test_mq.rs
@@ -1,4 +1,4 @@
-use nix::mqueue::{mq_open, mq_close, mq_send, mq_receive, mq_getattr};
+use nix::mqueue::{mq_open, mq_close, mq_send, mq_receive, mq_getattr, mq_unlink};
use nix::mqueue::{O_CREAT, O_WRONLY, O_RDONLY};
use nix::mqueue::MqAttr;
use nix::sys::stat::{S_IWUSR, S_IRUSR, S_IRGRP, S_IROTH};
@@ -9,11 +9,11 @@ use libc::c_long;
use nix::unistd::{fork, read, write, pipe};
use nix::unistd::Fork::{Child, Parent};
use nix::sys::wait::*;
-
-
+use nix::errno::Errno::*;
+use nix::Error::Sys;
#[test]
-fn mq_send_and_receive() {
+fn test_mq_send_and_receive() {
const MSG_SIZE: c_long = 32;
let attr = MqAttr::new(0, 10, MSG_SIZE, 0);
@@ -53,7 +53,7 @@ fn mq_send_and_receive() {
#[test]
-fn mq_get_attr() {
+fn test_mq_get_attr() {
const MSG_SIZE: c_long = 32;
let initial_attr = MqAttr::new(0, 10, MSG_SIZE, 0);
let mq_name = &CString::new("/attr_test_get_attr".as_bytes().as_ref()).unwrap();
@@ -62,3 +62,23 @@ fn mq_get_attr() {
assert!(read_attr.unwrap() == initial_attr);
mq_close(mqd).unwrap();
}
+
+#[test]
+fn test_mq_unlink() {
+ const MSG_SIZE: c_long = 32;
+ let initial_attr = MqAttr::new(0, 10, MSG_SIZE, 0);
+ let mq_name_opened = &CString::new("/mq_unlink_test".as_bytes().as_ref()).unwrap();
+ let mq_name_not_opened = &CString::new("/mq_unlink_test".as_bytes().as_ref()).unwrap();
+ let mqd = mq_open(mq_name_opened, O_CREAT | O_WRONLY, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH, &initial_attr).unwrap();
+
+ let res_unlink = mq_unlink(mq_name_opened);
+ assert!(res_unlink == Ok(()) );
+
+ let res_unlink_not_opened = mq_unlink(mq_name_not_opened);
+ assert!(res_unlink_not_opened == Err(Sys(ENOENT)) );
+
+ mq_close(mqd).unwrap();
+ let res_unlink_after_close = mq_unlink(mq_name_opened);
+ assert!(res_unlink_after_close == Err(Sys(ENOENT)) );
+
+}