From a298472da85e25755413912b96a6c736cdb9dbcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Oliveira?= Date: Fri, 19 Jul 2019 18:21:27 +0100 Subject: [PATCH] tokio-tls: enable `Send` and `Sync` (#1317) - update 0 as *mut () calls to std::ptr::null_mut() - impl Send and Sync for AllowStd --- tokio-tls/src/lib.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tokio-tls/src/lib.rs b/tokio-tls/src/lib.rs index f39342df6..a95d31da2 100644 --- a/tokio-tls/src/lib.rs +++ b/tokio-tls/src/lib.rs @@ -26,6 +26,7 @@ use std::future::Future; use std::io::{self, Read, Write}; use std::marker::Unpin; use std::pin::Pin; +use std::ptr::null_mut; use std::task::{Context, Poll}; use tokio_io::{AsyncRead, AsyncWrite}; @@ -77,10 +78,14 @@ where AllowStd: Read + Write, { fn drop(&mut self) { - (self.0).0.get_mut().context = 0 as *mut (); + (self.0).0.get_mut().context = null_mut(); } } +// *mut () context is neither Send nor Sync +unsafe impl Send for AllowStd {} +unsafe impl Sync for AllowStd {} + impl AllowStd where S: Unpin, @@ -234,11 +239,11 @@ where match (inner.f)(stream) { Ok(mut s) => { - s.get_mut().context = 0 as *mut (); + s.get_mut().context = null_mut(); Poll::Ready(Ok(StartedHandshake::Done(TlsStream(s)))) } Err(HandshakeError::WouldBlock(mut s)) => { - s.get_mut().context = 0 as *mut (); + s.get_mut().context = null_mut(); Poll::Ready(Ok(StartedHandshake::Mid(s))) } Err(HandshakeError::Failure(e)) => Poll::Ready(Err(e)), @@ -310,7 +315,7 @@ impl Future for MidHandshake { Ok(stream) => Poll::Ready(Ok(TlsStream(stream))), Err(HandshakeError::Failure(e)) => Poll::Ready(Err(e)), Err(HandshakeError::WouldBlock(mut s)) => { - s.get_mut().context = 0 as *mut (); + s.get_mut().context = null_mut(); mut_self.0 = Some(s); Poll::Pending }