From 2aac7ab959ca9856108acc2e46c6c75a017ef41b Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Wed, 22 Jan 2020 17:40:58 -0800 Subject: Agent, Sftp and File are now Send + Sync --- src/agent.rs | 6 ++++++ src/sftp.rs | 12 ++++++++++++ 2 files changed, 18 insertions(+) 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>, } +// 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>, } +// 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, } +// 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, -- cgit v1.2.3