Created
March 26, 2019 07:28
-
-
Save Cynede/08d2b3ef965f25590a40d7a9adea1095 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pub struct Sess<'s> { | |
| pub session: &'s ssh2::Session, | |
| pub channel: ssh2::Channel<'s> | |
| } | |
| rental! { | |
| pub mod rentals { | |
| use super::*; | |
| #[rental_mut] | |
| pub struct SSHSession { | |
| session_box: Box<ssh2::Session>, | |
| sess: Sess<'session_box>, | |
| } | |
| } | |
| } | |
| thread_local! { | |
| pub static SSH_RENTAL: RefCell<Option<self::rentals::SSHSession>> = { | |
| RefCell::new(None) | |
| }; | |
| } | |
| data::SSH_RENTAL.with(|ssh_session| { | |
| *ssh_session.borrow_mut() = Some( | |
| data::rentals::SSHSession::new(Box::new(sess), | |
| |ss| { Sess { session: &sess, channel: ss.channel_session().unwrap() } }) | |
| ); | |
| }); | |
| data::SSH_RENTAL.with(|ssh_session| { | |
| if let Some(ssh_session) = *ssh_session.borrow_mut() { | |
| let sess = ssh_session.ref_rent(|iref| iref); | |
| if let Err(why) = sess.channel.wait_close() { | |
| error!("Failed to leave channel: {}", why); | |
| } | |
| let longdescription: String = ::std::iter::repeat('A').take(10).collect(); | |
| if let Err(why) = sess.session.disconnect(None, &longdescription, None) { | |
| error!("Failed to disconnect from ssh: {}", why); | |
| } | |
| } | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment