diff options
author | Alex Crichton <alex@alexcrichton.com> | 2014-09-18 17:49:50 -0700 |
---|---|---|
committer | Alex Crichton <alex@alexcrichton.com> | 2014-09-18 17:49:50 -0700 |
commit | c45c5b0c55cc350d68008dedd6860fdaeaf0440d (patch) | |
tree | 1d395c2d66496e4f83afc2209009abcbbbdf906c /src/error.rs | |
parent | 4ec939804b0a94e6396c311dfb11293e7cac3058 (diff) | |
download | ssh2-rs-c45c5b0c55cc350d68008dedd6860fdaeaf0440d.zip |
Bind and tests many channel-based functions
Diffstat (limited to 'src/error.rs')
-rw-r--r-- | src/error.rs | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/error.rs b/src/error.rs index ae1f6c7..6d71362 100644 --- a/src/error.rs +++ b/src/error.rs @@ -22,14 +22,24 @@ impl Error { let rc = raw::libssh2_session_last_error(sess.raw(), &mut msg, 0 as *mut _, 0); if rc == 0 { return None } - Some(Error { - code: rc, - msg: str::raw::c_str_to_static_slice(msg as *const _), - marker: marker::NoCopy, - }) + Some(Error::new(rc, str::raw::c_str_to_static_slice(msg as *const _))) } } + /// Create a new error for the given code and message + pub fn new(code: libc::c_int, msg: &'static str) -> Error { + Error { + code: code, + msg: msg, + marker: marker::NoCopy, + } + } + + /// Generate an error that represents EOF + pub fn eof() -> Error { + Error::new(raw::LIBSSH2_ERROR_CHANNEL_EOF_SENT, "end of file") + } + /// Get the message corresponding to this error pub fn message(&self) -> &str { self.msg } } |