aboutsummaryrefslogtreecommitdiff
path: root/error.rs
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2013-10-23 21:10:38 -0700
committerSteven Fackler <[email protected]>2013-10-23 21:12:29 -0700
commiteea07ef137992c80ab80e17f28d71abf04ef9079 (patch)
tree3427c8b8524e4d759532c2834dcbe04a116c5134 /error.rs
parentRemove Sslv2 option (diff)
downloadrust-openssl-eea07ef137992c80ab80e17f28d71abf04ef9079.tar.xz
rust-openssl-eea07ef137992c80ab80e17f28d71abf04ef9079.zip
Slightly better error handling
Diffstat (limited to 'error.rs')
-rw-r--r--error.rs24
1 files changed, 22 insertions, 2 deletions
diff --git a/error.rs b/error.rs
index 90429996..5e5479f8 100644
--- a/error.rs
+++ b/error.rs
@@ -6,14 +6,34 @@ use super::ffi;
pub enum SslError {
StreamEof,
SslSessionClosed,
- UnknownError(c_ulong)
+ UnknownError {
+ library: u8,
+ function: u16,
+ reason: u16
+ }
+}
+
+fn get_lib(err: c_ulong) -> u8 {
+ ((err >> 24) & 0xff) as u8
+}
+
+fn get_func(err: c_ulong) -> u16 {
+ ((err >> 12) & 0xfff) as u16
+}
+
+fn get_reason(err: c_ulong) -> u16 {
+ (err & 0xfff) as u16
}
impl SslError {
pub fn get() -> Option<SslError> {
match unsafe { ffi::ERR_get_error() } {
0 => None,
- err => Some(UnknownError(err))
+ err => Some(UnknownError {
+ library: get_lib(err),
+ function: get_func(err),
+ reason: get_reason(err)
+ })
}
}
}