about summary refs log tree commit diff
path: root/src/error.rs
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@gmail.com>2017-10-15T23·08+0200
committerVincent Ambo <tazjin@gmail.com>2017-10-15T23·08+0200
commit7dc6144e3fe53d611a8a83ad78fed1dc37c785e6 (patch)
treed451d4a76f60141393fcf6a6551880c1b52204e4 /src/error.rs
parent1f1a74108e74a50c39eeac37bb3a91cb49c1d35d (diff)
feat: Implement high-level POSIX message queue API
Implements a high-level API on top of POSIX message queues
(mq_overview(7)).

This API can be used to perform local RPC between processes that need
to exchange messages *fast* (or *easy*) with priority ordering.

The methods are mostly documented but there are still two corner cases
that need to be looked at and a lot of tests missing.
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/error.rs b/src/error.rs
index b288723e5664..1a0c069a89b0 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -1,6 +1,8 @@
 use nix;
 use std::error;
 use std::fmt;
+use std::io;
+use std::num;
 
 /// This module implements a simple error type to match the errors that can be thrown from the C
 /// functions as well as some extra errors resulting from internal validations.
@@ -19,6 +21,13 @@ use std::fmt;
 
 #[derive(Debug)]
 pub enum Error {
+    // These errors are raised inside of the library
+    InvalidQueueName(&'static str),
+    ValueReadingError(io::Error),
+    MessageSizeExceeded(),
+    MaximumMessageSizeExceeded(),
+    MaximumMessageCountExceeded(),
+
     // These errors match what is described in the man pages (from mq_overview(7) onwards).
     PermissionDenied(),
     InvalidQueueDescriptor(),
@@ -45,6 +54,12 @@ impl error::Error for Error {
     fn description(&self) -> &str {
         use Error::*;
         match *self {
+            // This error contains more sensible description strings already
+            InvalidQueueName(e) => e,
+            ValueReadingError(_) => "error reading system configuration for message queues",
+            MessageSizeExceeded() => "message is larger than maximum size for specified queue",
+            MaximumMessageSizeExceeded() => "specified queue message size exceeds system maximum",
+            MaximumMessageCountExceeded() => "specified queue message count exceeds system maximum",
             PermissionDenied() => "permission to the specified queue was denied",
             InvalidQueueDescriptor() => "the internal queue descriptor was invalid",
             QueueCallInterrupted() => "queue method interrupted by signal",
@@ -52,8 +67,10 @@ impl error::Error for Error {
             QueueNotFound() => "the specified queue could not be found",
             InsufficientMemory() => "insufficient memory to call queue method",
             InsufficientSpace() => "insufficient space to call queue method",
-            ProcessFileDescriptorLimitReached() => "max. number of process file descriptors reached",
-            SystemFileDescriptorLimitReached() => "max. number of system file descriptors reached",
+            ProcessFileDescriptorLimitReached() =>
+                "maximum number of process file descriptors reached",
+            SystemFileDescriptorLimitReached() =>
+                "maximum number of system file descriptors reached",
             UnknownForeignError(_) => "unknown foreign error occured: please report a bug!",
             UnknownInternalError(_) => "unknown internal error occured: please report a bug!",
         }
@@ -79,6 +96,22 @@ impl From<nix::Error> for Error {
     }
 }
 
+// This implementation is used when reading system queue settings.
+impl From<io::Error> for Error {
+    fn from(e: io::Error) -> Self {
+        Error::ValueReadingError(e)
+    }
+}
+
+// This implementation is used when parsing system queue settings. The unknown error is returned
+// here because the system is probably seriously broken if those files don't contain numbers.
+impl From<num::ParseIntError> for Error {
+    fn from(_: num::ParseIntError) -> Self {
+        Error::UnknownInternalError(None)
+    }
+}
+
+
 fn match_errno(err: nix::Errno) -> Error {
     use nix::errno::*;