@@ -25,7 +25,8 @@ pub use connector::TlsConnector as TlsConnector;
25
25
pub use errors:: Error as Error ;
26
26
27
27
use std:: io:: { self , Read , Write } ;
28
- use std:: task:: Waker ;
28
+ use std:: pin:: Pin ;
29
+ use std:: task:: Context ;
29
30
30
31
use futures:: compat:: Compat ;
31
32
use futures:: io:: { AsyncRead , AsyncWrite } ;
@@ -56,12 +57,18 @@ impl<S> TlsStream<S> {
56
57
pub fn get_mut ( & mut self ) -> & mut native_tls:: TlsStream < Compat < S > > {
57
58
& mut self . inner
58
59
}
60
+
61
+ fn inner < ' a > ( self : Pin < & ' a mut Self > ) -> & ' a mut native_tls:: TlsStream < Compat < S > > {
62
+ unsafe {
63
+ & mut Pin :: get_unchecked_mut ( self ) . inner
64
+ }
65
+ }
59
66
}
60
67
61
- impl < S : AsyncRead + AsyncWrite > AsyncRead for TlsStream < S > {
62
- fn poll_read ( & mut self , _lw : & Waker , buf : & mut [ u8 ] )
68
+ impl < S : AsyncRead + AsyncWrite + Unpin > AsyncRead for TlsStream < S > {
69
+ fn poll_read ( mut self : Pin < & mut Self > , _cx : & mut Context < ' _ > , buf : & mut [ u8 ] )
63
70
-> Poll < Result < usize , io:: Error > > {
64
- match self . inner . read ( buf) {
71
+ match self . as_mut ( ) . inner ( ) . read ( buf) {
65
72
Ok ( sz) => Poll :: Ready ( Ok ( sz) ) ,
66
73
Err ( ref e) if e. kind ( ) == io:: ErrorKind :: WouldBlock => {
67
74
Poll :: Pending
@@ -71,10 +78,10 @@ impl<S: AsyncRead + AsyncWrite> AsyncRead for TlsStream<S> {
71
78
}
72
79
}
73
80
74
- impl < S : AsyncRead + AsyncWrite > AsyncWrite for TlsStream < S > {
75
- fn poll_write ( & mut self , _lw : & Waker , buf : & [ u8 ] )
81
+ impl < S : AsyncRead + AsyncWrite + Unpin > AsyncWrite for TlsStream < S > {
82
+ fn poll_write ( mut self : Pin < & mut Self > , _cx : & mut Context < ' _ > , buf : & [ u8 ] )
76
83
-> Poll < Result < usize , io:: Error > > {
77
- match self . inner . write ( buf) {
84
+ match self . as_mut ( ) . inner ( ) . write ( buf) {
78
85
Ok ( sz) => Poll :: Ready ( Ok ( sz) ) ,
79
86
Err ( ref e) if e. kind ( ) == io:: ErrorKind :: WouldBlock => {
80
87
Poll :: Pending
@@ -83,8 +90,8 @@ impl<S: AsyncRead + AsyncWrite> AsyncWrite for TlsStream<S> {
83
90
}
84
91
}
85
92
86
- fn poll_flush ( & mut self , _lw : & Waker ) -> Poll < Result < ( ) , io:: Error > > {
87
- match self . inner . flush ( ) {
93
+ fn poll_flush ( mut self : Pin < & mut Self > , _cx : & mut Context < ' _ > ) -> Poll < Result < ( ) , io:: Error > > {
94
+ match self . as_mut ( ) . inner ( ) . flush ( ) {
88
95
Ok ( sz) => Poll :: Ready ( Ok ( sz) ) ,
89
96
Err ( ref e) if e. kind ( ) == io:: ErrorKind :: WouldBlock => {
90
97
Poll :: Pending
@@ -93,8 +100,8 @@ impl<S: AsyncRead + AsyncWrite> AsyncWrite for TlsStream<S> {
93
100
}
94
101
}
95
102
96
- fn poll_close ( & mut self , _lw : & Waker ) -> Poll < Result < ( ) , io:: Error > > {
97
- match self . inner . shutdown ( ) {
103
+ fn poll_close ( mut self : Pin < & mut Self > , _cx : & mut Context < ' _ > ) -> Poll < Result < ( ) , io:: Error > > {
104
+ match self . as_mut ( ) . inner ( ) . shutdown ( ) {
98
105
Ok ( sz) => Poll :: Ready ( Ok ( sz) ) ,
99
106
Err ( ref e) if e. kind ( ) == io:: ErrorKind :: WouldBlock => {
100
107
Poll :: Pending
0 commit comments