@@ -92,9 +92,13 @@ impl<T: AsyncRead + AsyncWrite> Buffered<T> {
9292 }
9393 }
9494
95- fn read_from_io ( & mut self ) -> Poll < usize , io:: Error > {
95+ pub fn read_from_io ( & mut self ) -> Poll < usize , io:: Error > {
9696 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.
98102 if self . read_buf . remaining_mut ( ) < INIT_BUFFER_SIZE {
99103 self . read_buf . reserve ( INIT_BUFFER_SIZE ) ;
100104 unsafe { // Zero out unused memory
@@ -103,13 +107,11 @@ impl<T: AsyncRead + AsyncWrite> Buffered<T> {
103107 ptr:: write_bytes ( buf. as_mut_ptr ( ) , 0 , len) ;
104108 }
105109 }
106- self . read_blocked = false ;
107- unsafe { // Can we use AsyncRead::read_buf instead?
110+ unsafe {
108111 let n = match self . io . read ( self . read_buf . bytes_mut ( ) ) {
109112 Ok ( n) => n,
110113 Err ( e) => {
111114 if e. kind ( ) == io:: ErrorKind :: WouldBlock {
112- // TODO: Push this out, ideally, into http::Conn.
113115 self . read_blocked = true ;
114116 return Ok ( Async :: NotReady ) ;
115117 }
0 commit comments