summaryrefslogtreecommitdiff
path: root/src/mqueue.rs
diff options
context:
space:
mode:
authorMarkus Jais <markusjais@gmx.de>2015-09-19 17:02:24 +0200
committerCarl Lerche <me@carllerche.com>2015-09-28 13:08:16 -0700
commit5ef1f7acd3b325fc642aa4af6ff25a9dfd0ac618 (patch)
tree41b9fcf920137f01b01ad0e7bf3f5b4827f641f1 /src/mqueue.rs
parent8da9b314e973e756c8384a6110fb85c899d64561 (diff)
downloadnix-5ef1f7acd3b325fc642aa4af6ff25a9dfd0ac618.zip
added convenience functions for setting O_NONBLOCK on message queues
Diffstat (limited to 'src/mqueue.rs')
-rw-r--r--src/mqueue.rs28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/mqueue.rs b/src/mqueue.rs
index 460c7e89..1a2c2ead 100644
--- a/src/mqueue.rs
+++ b/src/mqueue.rs
@@ -1,3 +1,7 @@
+//! Posis Message Queue functions
+//!
+//! [Further reading and details on the C API](http://man7.org/linux/man-pages/man7/mq_overview.7.html)
+
use {Error, Result, from_ffi};
use errno::Errno;
@@ -124,7 +128,11 @@ pub fn mq_getattr(mqd: MQd) -> Result<MqAttr> {
Ok(attr)
}
-
+/// Set the attributes of the message queue. Only O_NONBLOCK can be set, everything else will be ignored
+/// Returns the old attributes
+/// It is recommend to use the mq_set_nonblock() and mq_remove_nonblock() convenience functions as they are easier to use
+///
+/// [Further reading](http://man7.org/linux/man-pages/man3/mq_setattr.3.html)
pub fn mq_setattr(mqd: MQd, newattr: &MqAttr) -> Result<MqAttr> {
let mut attr = MqAttr::new(0, 0, 0, 0);
let res = unsafe { ffi::mq_setattr(mqd, newattr as *const MqAttr, &mut attr) };
@@ -133,3 +141,21 @@ pub fn mq_setattr(mqd: MQd, newattr: &MqAttr) -> Result<MqAttr> {
}
Ok(attr)
}
+
+/// Convenience function.
+/// Sets the O_NONBLOCK attribute for a given message queue descriptor
+/// Returns the old attributes
+pub fn mq_set_nonblock(mqd: MQd) -> Result<(MqAttr)> {
+ let oldattr = try!(mq_getattr(mqd));
+ let newattr = MqAttr::new(O_NONBLOCK.bits() as c_long, oldattr.mq_maxmsg, oldattr.mq_msgsize, oldattr.mq_curmsgs);
+ mq_setattr(mqd, &newattr)
+}
+
+/// Convenience function.
+/// Removes O_NONBLOCK attribute for a given message queue descriptor
+/// Returns the old attributes
+pub fn mq_remove_nonblock(mqd: MQd) -> Result<(MqAttr)> {
+ let oldattr = try!(mq_getattr(mqd));
+ let newattr = MqAttr::new(0, oldattr.mq_maxmsg, oldattr.mq_msgsize, oldattr.mq_curmsgs);
+ mq_setattr(mqd, &newattr)
+}