From b7532e93a4a31b96fff2348e292f10aec89014cd Mon Sep 17 00:00:00 2001 From: bold Date: Thu, 26 Dec 2019 16:06:18 +0100 Subject: export block directions --- src/lib.rs | 2 +- src/session.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) (limited to 'src') 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 { -- cgit v1.2.3