@@ -2,7 +2,7 @@ use super::abi;
22use crate :: {
33 cmp,
44 ffi:: CStr ,
5- io:: { self , ErrorKind , IoSlice , IoSliceMut } ,
5+ io:: { self , BorrowedBuf , BorrowedCursor , ErrorKind , IoSlice , IoSliceMut } ,
66 mem,
77 net:: { Shutdown , SocketAddr } ,
88 ptr, str,
@@ -294,19 +294,30 @@ impl Socket {
294294 self . 0 . duplicate ( ) . map ( Socket )
295295 }
296296
297- fn recv_with_flags ( & self , buf : & mut [ u8 ] , flags : c_int ) -> io:: Result < usize > {
297+ fn recv_with_flags ( & self , mut buf : BorrowedCursor < ' _ > , flags : c_int ) -> io:: Result < ( ) > {
298298 let ret = cvt ( unsafe {
299- netc:: recv ( self . 0 . raw ( ) , buf. as_mut_ptr ( ) as * mut c_void , buf. len ( ) , flags)
299+ netc:: recv ( self . 0 . raw ( ) , buf. as_mut ( ) . as_mut_ptr ( ) . cast ( ) , buf. capacity ( ) , flags)
300300 } ) ?;
301- Ok ( ret as usize )
301+ unsafe {
302+ buf. advance ( ret as usize ) ;
303+ }
304+ Ok ( ( ) )
302305 }
303306
304307 pub fn read ( & self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
305- self . recv_with_flags ( buf, 0 )
308+ let mut buf = BorrowedBuf :: from ( buf) ;
309+ self . recv_with_flags ( buf. unfilled ( ) , 0 ) ?;
310+ Ok ( buf. len ( ) )
306311 }
307312
308313 pub fn peek ( & self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
309- self . recv_with_flags ( buf, MSG_PEEK )
314+ let mut buf = BorrowedBuf :: from ( buf) ;
315+ self . recv_with_flags ( buf. unfilled ( ) , MSG_PEEK ) ?;
316+ Ok ( buf. len ( ) )
317+ }
318+
319+ pub fn read_buf ( & self , buf : BorrowedCursor < ' _ > ) -> io:: Result < ( ) > {
320+ self . recv_with_flags ( buf, 0 )
310321 }
311322
312323 pub fn read_vectored ( & self , bufs : & mut [ IoSliceMut < ' _ > ] ) -> io:: Result < usize > {
0 commit comments