about summary refs log tree commit diff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@gmail.com>2017-10-16T00·00+0200
committerVincent Ambo <tazjin@gmail.com>2017-10-16T00·00+0200
commit3144b61ccc2ec024c19ccb41ff6964a86203ee14 (patch)
treeda3aa853e94d6688dd9e14a5701f664ef39e21cf /src/lib.rs
parent6be954393b452275445108098d3ea24af25248b7 (diff)
feat(lib): Implement Drop trait for Queue
Implements the Drop trait to take care of closing the queue descriptor
when a Queue instance is dropped.
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 475b2c0f44d2..cc3939d94cad 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -9,6 +9,7 @@ use std::ffi::CString;
 use std::fs::File;
 use std::io::Read;
 use std::string::ToString;
+use std::ops::Drop;
 
 mod error;
 
@@ -220,6 +221,15 @@ impl Queue {
     }
 }
 
+impl Drop for Queue {
+    fn drop(&mut self) {
+        // Attempt to close the queue descriptor and discard any possible errors.
+        // The only error thrown in the C-code is EINVAL, which would mean that the
+        // descriptor has already been closed.
+        mqueue::mq_close(self.queue_descriptor).ok();
+    }
+}
+
 // Creates the default queue mode (0600).
 fn default_mode() -> stat::Mode {
     let mut mode = stat::Mode::empty();