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 /src/sftp.rs | |
parent | df9a7c058c5ea6bd634067bbf623d0b57bb5f992 (diff) | |
download | ssh2-rs-2aac7ab959ca9856108acc2e46c6c75a017ef41b.zip |
Agent, Sftp and File are now Send + Sync
Diffstat (limited to 'src/sftp.rs')
-rw-r--r-- | src/sftp.rs | 12 |
1 files changed, 12 insertions, 0 deletions
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, |