summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWez Furlong <wez@wezfurlong.org>2020-01-18 16:33:07 -0800
committerWez Furlong <wez@wezfurlong.org>2020-01-18 16:33:07 -0800
commit8564d28262161917bb9f8070996f97a5a87003f0 (patch)
tree02be818ad0629317dad4b8de5a1c146e2af91d21 /src
parent92f466c07ccded1fe58f245320542cca69267e7e (diff)
downloadssh2-rs-8564d28262161917bb9f8070996f97a5a87003f0.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/listener.rs7
1 files changed, 7 insertions, 0 deletions
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<Mutex<SessionInner>>,
}
+// 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<Channel, Error> {
@@ -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);
}