summaryrefslogtreecommitdiff
path: root/src/error.rs
diff options
context:
space:
mode:
authorWez Furlong <wez@wezfurlong.org>2019-07-24 12:41:13 -0700
committerWez Furlong <wez@wezfurlong.org>2019-07-29 08:55:06 -0700
commit59ce6cc1cb9a6ee3dcde05af58979d2e189870db (patch)
tree99c8a72512a2df393f1569c2481f292e5440afdc /src/error.rs
parente010cbfe9bd26b64be2610b29703f50e50f0b4f8 (diff)
downloadssh2-rs-59ce6cc1cb9a6ee3dcde05af58979d2e189870db.zip
Map EAGAIN errors appropriately
When the channel is set to non-blocking mode, take care to map the underlying ssh2 error code to the WouldBlock error kind so that embedding applications can correctly handle that situation.
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs
index d5dd397..916cc51 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -139,6 +139,16 @@ impl Error {
}
}
+impl From<Error> for std::io::Error {
+ fn from(err: Error) -> std::io::Error {
+ let kind = match err.code {
+ raw::LIBSSH2_ERROR_EAGAIN => std::io::ErrorKind::WouldBlock,
+ _ => std::io::ErrorKind::Other,
+ };
+ std::io::Error::new(kind, err.msg)
+ }
+}
+
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "[{}] {}", self.code, self.msg)