about summary refs log tree commit diff
path: root/src/lib.rs
diff options
context:
space:
mode:
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();