@@ -92,9 +92,13 @@ impl<T: AsyncRead + AsyncWrite> Buffered<T> {
92
92
}
93
93
}
94
94
95
- fn read_from_io ( & mut self ) -> Poll < usize , io:: Error > {
95
+ pub fn read_from_io ( & mut self ) -> Poll < usize , io:: Error > {
96
96
use bytes:: BufMut ;
97
- // TODO: Investigate if we still need these unsafe blocks
97
+ self . read_blocked = false ;
98
+ //TODO: use io.read_buf(), so we don't have to zero memory
99
+ //Reason this doesn't use it yet is because benchmarks show the
100
+ //slightest **decrease** in performance. Switching should be done
101
+ //when it doesn't cost anything.
98
102
if self . read_buf . remaining_mut ( ) < INIT_BUFFER_SIZE {
99
103
self . read_buf . reserve ( INIT_BUFFER_SIZE ) ;
100
104
unsafe { // Zero out unused memory
@@ -103,13 +107,11 @@ impl<T: AsyncRead + AsyncWrite> Buffered<T> {
103
107
ptr:: write_bytes ( buf. as_mut_ptr ( ) , 0 , len) ;
104
108
}
105
109
}
106
- self . read_blocked = false ;
107
- unsafe { // Can we use AsyncRead::read_buf instead?
110
+ unsafe {
108
111
let n = match self . io . read ( self . read_buf . bytes_mut ( ) ) {
109
112
Ok ( n) => n,
110
113
Err ( e) => {
111
114
if e. kind ( ) == io:: ErrorKind :: WouldBlock {
112
- // TODO: Push this out, ideally, into http::Conn.
113
115
self . read_blocked = true ;
114
116
return Ok ( Async :: NotReady ) ;
115
117
}
0 commit comments