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 }