summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbold <bold@cryptoguru.com>2019-12-26 16:06:18 +0100
committerWez Furlong <wez@wezfurlong.org>2020-01-03 22:02:46 -0800
commitb7532e93a4a31b96fff2348e292f10aec89014cd (patch)
tree89a63f98c5cf46876f52ec8306542a33b8834a61 /src
parentdcedc9056d2a0681027b795393fca111b5cd03aa (diff)
downloadssh2-rs-b7532e93a4a31b96fff2348e292f10aec89014cd.zip
export block directions
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs2
-rw-r--r--src/session.rs28
2 files changed, 29 insertions, 1 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 4c57256..8f04390 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -147,7 +147,7 @@ pub use error::Error;
pub use knownhosts::{Host, Hosts, KnownHosts};
pub use listener::Listener;
use session::SessionInner;
-pub use session::{KeyboardInteractivePrompt, Prompt, ScpFileStat, Session};
+pub use session::{KeyboardInteractivePrompt, Prompt, ScpFileStat, Session, BlockDirections};
pub use sftp::{File, FileStat, FileType, OpenType};
pub use sftp::{OpenFlags, RenameFlags, Sftp};
pub use DisconnectCode::{AuthCancelledByUser, TooManyConnections};
diff --git a/src/session.rs b/src/session.rs
index d1b3da2..364ddd7 100644
--- a/src/session.rs
+++ b/src/session.rs
@@ -92,6 +92,19 @@ pub struct ScpFileStat {
stat: libc::stat,
}
+/// The io direction an application has to wait for in order not to block.
+#[derive(Debug, PartialEq)]
+pub enum BlockDirections {
+ /// No direction blocked.
+ None,
+ /// Inbound direction blocked.
+ Inbound,
+ /// Outbound direction blockd.
+ Outbound,
+ /// Inbound and Outbound direction blocked.
+ Both,
+}
+
impl Session {
/// Initializes an SSH session object.
///
@@ -914,6 +927,21 @@ impl Session {
pub fn rc(&self, rc: c_int) -> Result<(), Error> {
self.inner.rc(rc)
}
+
+ /// Returns the blocked io directions that the application needs to wait for.
+ ///
+ /// This function should be used after an error of type `WouldBlock` is returned to
+ /// find out the socket events the application has to wait for.
+ pub fn block_directions(&self) -> BlockDirections {
+ let dir = unsafe { raw::libssh2_session_block_directions(self.inner.raw) };
+ match dir {
+ raw::LIBSSH2_SESSION_BLOCK_INBOUND => BlockDirections::Inbound,
+ raw::LIBSSH2_SESSION_BLOCK_OUTBOUND => BlockDirections::Outbound,
+ x if x == raw::LIBSSH2_SESSION_BLOCK_INBOUND | raw::LIBSSH2_SESSION_BLOCK_OUTBOUND
+ => BlockDirections::Both,
+ _ => BlockDirections::None,
+ }
+ }
}
impl SessionInner {