@@ -2,7 +2,7 @@ use super::abi;
2
2
use crate :: {
3
3
cmp,
4
4
ffi:: CStr ,
5
- io:: { self , ErrorKind , IoSlice , IoSliceMut } ,
5
+ io:: { self , BorrowedBuf , BorrowedCursor , ErrorKind , IoSlice , IoSliceMut } ,
6
6
mem,
7
7
net:: { Shutdown , SocketAddr } ,
8
8
ptr, str,
@@ -294,19 +294,30 @@ impl Socket {
294
294
self . 0 . duplicate ( ) . map ( Socket )
295
295
}
296
296
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 < ( ) > {
298
298
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)
300
300
} ) ?;
301
- Ok ( ret as usize )
301
+ unsafe {
302
+ buf. advance ( ret as usize ) ;
303
+ }
304
+ Ok ( ( ) )
302
305
}
303
306
304
307
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 ( ) )
306
311
}
307
312
308
313
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 )
310
321
}
311
322
312
323
pub fn read_vectored ( & self , bufs : & mut [ IoSliceMut < ' _ > ] ) -> io:: Result < usize > {
0 commit comments