From 92f466c07ccded1fe58f245320542cca69267e7e Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 18 Jan 2020 16:28:12 -0800 Subject: ChannelInner is Send + Sync This allows Channel and Stream to be Send --- src/channel.rs | 6 ++++++ tests/all/channel.rs | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/src/channel.rs b/src/channel.rs index 1169a65..82ac981 100644 --- a/src/channel.rs +++ b/src/channel.rs @@ -14,6 +14,12 @@ struct ChannelInner { read_limit: Mutex>, } +// ChannelInner 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 ChannelInner {} +unsafe impl Sync for ChannelInner {} + struct LockedChannel<'a> { raw: *mut raw::LIBSSH2_CHANNEL, sess: MutexGuard<'a, SessionInner>, diff --git a/tests/all/channel.rs b/tests/all/channel.rs index 8b624ac..2f14d01 100644 --- a/tests/all/channel.rs +++ b/tests/all/channel.rs @@ -24,6 +24,13 @@ fn consume_stdio(channel: &mut Channel) -> (String, String) { fn smoke() { let sess = ::authed_session(); let mut channel = sess.channel_session().unwrap(); + + fn must_be_send(_: &T) -> bool { + true + } + assert!(must_be_send(&channel)); + assert!(must_be_send(&channel.stream(0))); + channel.flush().unwrap(); channel.exec("true").unwrap(); consume_stdio(&mut channel); -- cgit v1.2.3