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.
This commit is contained in:
Vincent Ambo 2017-10-16 02:00:32 +02:00
parent 6be954393b
commit 3144b61ccc

View file

@ -9,6 +9,7 @@ use std::ffi::CString;
use std::fs::File; use std::fs::File;
use std::io::Read; use std::io::Read;
use std::string::ToString; use std::string::ToString;
use std::ops::Drop;
mod error; 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). // Creates the default queue mode (0600).
fn default_mode() -> stat::Mode { fn default_mode() -> stat::Mode {
let mut mode = stat::Mode::empty(); let mut mode = stat::Mode::empty();