From 8564d28262161917bb9f8070996f97a5a87003f0 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 18 Jan 2020 16:33:07 -0800 Subject: make Listener Send + Sync @richardwhiuk requested this. While it is safe to move to another thread, it will still lock internally, and if you are in blocking mode that may be undesirable. --- src/listener.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/listener.rs b/src/listener.rs index a1a4c8e..e0dc315 100644 --- a/src/listener.rs +++ b/src/listener.rs @@ -11,6 +11,12 @@ pub struct Listener { sess: Arc>, } +// Listener 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 Listener {} +unsafe impl Sync for Listener {} + impl Listener { /// Accept a queued connection from this listener. pub fn accept(&mut self) -> Result { @@ -40,6 +46,7 @@ impl Listener { impl Drop for Listener { fn drop(&mut self) { + let _sess = self.sess.lock(); unsafe { let _ = raw::libssh2_channel_forward_cancel(self.raw); } -- cgit v1.2.3