diff options
author | Wez Furlong <wez@wezfurlong.org> | 2020-01-22 17:40:58 -0800 |
---|---|---|
committer | Wez Furlong <wez@wezfurlong.org> | 2020-01-22 17:40:58 -0800 |
commit | 2aac7ab959ca9856108acc2e46c6c75a017ef41b (patch) | |
tree | 8a37ba2f870984698b98c2cfe419d2a0591f956f | |
parent | df9a7c058c5ea6bd634067bbf623d0b57bb5f992 (diff) | |
download | ssh2-rs-2aac7ab959ca9856108acc2e46c6c75a017ef41b.zip |
Agent, Sftp and File are now Send + Sync
-rw-r--r-- | src/agent.rs | 6 | ||||
-rw-r--r-- | src/sftp.rs | 12 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/agent.rs b/src/agent.rs index dbafb1d..85ba4e6 100644 --- a/src/agent.rs +++ b/src/agent.rs @@ -14,6 +14,12 @@ pub struct Agent { sess: Arc<Mutex<SessionInner>>, } +// Agent is both Send and Sync; the compiler can't see it because it +// is pessimistic about the raw pointer. We use Arc/Mutex to guard accessing +// the raw pointer so we are safe for both. +unsafe impl Send for Agent {} +unsafe impl Sync for Agent {} + /// A public key which is extracted from an SSH agent. #[derive(Debug, PartialEq, Eq)] pub struct PublicKey { diff --git a/src/sftp.rs b/src/sftp.rs index 25c3a74..491b447 100644 --- a/src/sftp.rs +++ b/src/sftp.rs @@ -14,6 +14,12 @@ struct SftpInner { sess: Arc<Mutex<SessionInner>>, } +// Sftp is both Send and Sync; the compiler can't see it because it +// is pessimistic about the raw pointer. We use Arc/Mutex to guard accessing +// the raw pointer so we are safe for both. +unsafe impl Send for Sftp {} +unsafe impl Sync for Sftp {} + /// A handle to a remote filesystem over SFTP. /// /// Instances are created through the `sftp` method on a `Session`. @@ -31,6 +37,12 @@ struct FileInner { sftp: Arc<SftpInner>, } +// FileInner is both Send and Sync; the compiler can't see it because it +// is pessimistic about the raw pointer. We use Arc/Mutex to guard accessing +// the raw pointer so we are safe for both. +unsafe impl Send for FileInner {} +unsafe impl Sync for FileInner {} + struct LockedFile<'file> { sess: MutexGuard<'file, SessionInner>, raw: *mut raw::LIBSSH2_SFTP_HANDLE, |