File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- use std:: marker:: PhantomData ;
1+ use std:: { marker:: PhantomData , mem :: MaybeUninit } ;
22
33cfg_if:: cfg_if! {
44 if #[ cfg( windows) ] {
@@ -93,10 +93,11 @@ impl<'a> CMsgBuilder<'a> {
9393 ///
9494 /// This function will panic if the buffer is too short or not properly
9595 /// aligned.
96- pub fn new ( buffer : & ' a mut [ u8 ] ) -> Self {
97- buffer. fill ( 0 ) ;
96+ pub fn new ( buffer : & ' a mut [ MaybeUninit < u8 > ] ) -> Self {
97+ // TODO: optimize zeroing
98+ buffer. fill ( MaybeUninit :: new ( 0 ) ) ;
9899 Self {
99- inner : sys:: CMsgIter :: new ( buffer. as_ptr ( ) , buffer. len ( ) ) ,
100+ inner : sys:: CMsgIter :: new ( buffer. as_ptr ( ) . cast ( ) , buffer. len ( ) ) ,
100101 len : 0 ,
101102 _p : PhantomData ,
102103 }
Original file line number Diff line number Diff line change 1+ use std:: mem:: MaybeUninit ;
2+
13use aligned_array:: { A8 , Aligned } ;
2- use compio_buf:: IoBuf ;
4+ use compio_buf:: { IoBuf , IoBufMut } ;
35use compio_net:: { CMsgBuilder , CMsgIter } ;
46
57#[ test]
68fn test_cmsg ( ) {
79 let mut buf: Aligned < A8 , [ u8 ; 64 ] > = Aligned ( [ 0u8 ; 64 ] ) ;
8- let mut builder = CMsgBuilder :: new ( buf. as_mut_slice ( ) ) ;
10+ let mut builder = CMsgBuilder :: new ( buf. as_uninit ( ) ) ;
911
1012 builder. try_push ( 0 , 0 , ( ) ) . unwrap ( ) ; // 16 / 12
1113 builder. try_push ( 1 , 1 , u32:: MAX ) . unwrap ( ) ; // 16 + 4 + 4 / 12 + 4
@@ -36,13 +38,13 @@ fn test_cmsg() {
3638#[ test]
3739#[ should_panic]
3840fn invalid_buffer_length ( ) {
39- let mut buf = [ 0u8 ; 1 ] ;
41+ let mut buf = [ MaybeUninit :: new ( 0u8 ) ; 1 ] ;
4042 CMsgBuilder :: new ( & mut buf) ;
4143}
4244
4345#[ test]
4446#[ should_panic]
4547fn invalid_buffer_alignment ( ) {
46- let mut buf = [ 0u8 ; 64 ] ;
48+ let mut buf = [ MaybeUninit :: new ( 0u8 ) ; 64 ] ;
4749 CMsgBuilder :: new ( & mut buf[ 1 ..] ) ;
4850}
Original file line number Diff line number Diff line change @@ -68,7 +68,7 @@ impl<const N: usize> Ancillary<N> {
6868 fn new ( ) -> Self {
6969 Self {
7070 inner : [ 0u8 ; N ] ,
71- len : N ,
71+ len : 0 ,
7272 _align : [ ] ,
7373 }
7474 }
@@ -85,16 +85,6 @@ impl<const N: usize> SetLen for Ancillary<N> {
8585 debug_assert ! ( len <= N ) ;
8686 self . len = len;
8787 }
88-
89- // FIXME(George-Miao, AsakuraMizu): this is not the desired behavior, only
90- // served as a workaround for now.
91- // See: https://github.com/compio-rs/compio/issues/580
92- unsafe fn advance_to ( & mut self , len : usize )
93- where
94- Self : IoBuf ,
95- {
96- unsafe { self . set_len ( len) } ;
97- }
9888}
9989
10090impl < const N : usize > IoBufMut for Ancillary < N > {
@@ -423,7 +413,7 @@ impl Socket {
423413 let ecn = transmit. ecn . map_or ( 0 , |x| x as u8 ) ;
424414
425415 let mut control = Ancillary :: < CMSG_LEN > :: new ( ) ;
426- let mut builder = CMsgBuilder :: new ( & mut control) ;
416+ let mut builder = CMsgBuilder :: new ( control. as_uninit ( ) ) ;
427417
428418 // ECN
429419 if is_ipv4 {
You can’t perform that action at this time.
0 commit comments