@@ -636,3 +636,70 @@ impl<'name, 'bufs, 'control> fmt::Debug for MsgHdr<'name, 'bufs, 'control> {
636
636
"MsgHdr" . fmt ( fmt)
637
637
}
638
638
}
639
+
640
+ /// Configuration of a `recvmsg(2)` system call.
641
+ ///
642
+ /// This wraps `msghdr` on Unix and `WSAMSG` on Windows. Also see [`MsgHdr`] for
643
+ /// the variant used by `sendmsg(2)`.
644
+ #[ cfg( not( target_os = "redox" ) ) ]
645
+ pub struct MsgHdrMut < ' addr , ' bufs , ' control > {
646
+ inner : sys:: msghdr ,
647
+ #[ allow( clippy:: type_complexity) ]
648
+ _lifetimes : PhantomData < (
649
+ & ' addr mut SockAddr ,
650
+ & ' bufs mut MaybeUninitSlice < ' bufs > ,
651
+ & ' control mut [ u8 ] ,
652
+ ) > ,
653
+ }
654
+
655
+ #[ cfg( not( target_os = "redox" ) ) ]
656
+ impl < ' addr , ' bufs , ' control > MsgHdrMut < ' addr , ' bufs , ' control > {
657
+ /// Create a new `MsgHdrMut` with all empty/zero fields.
658
+ #[ allow( clippy:: new_without_default) ]
659
+ pub fn new ( ) -> MsgHdrMut < ' addr , ' bufs , ' control > {
660
+ // SAFETY: all zero is valid for `msghdr` and `WSAMSG`.
661
+ MsgHdrMut {
662
+ inner : unsafe { mem:: zeroed ( ) } ,
663
+ _lifetimes : PhantomData ,
664
+ }
665
+ }
666
+
667
+ /// Set the mutable address (name) of the message.
668
+ ///
669
+ /// Corresponds to setting `msg_name` and `msg_namelen` on Unix and `name`
670
+ /// and `namelen` on Windows.
671
+ pub fn with_addr ( mut self , addr : & ' addr mut SockAddr ) -> Self {
672
+ sys:: set_msghdr_name ( & mut self . inner , addr) ;
673
+ self
674
+ }
675
+
676
+ /// Set the mutable buffer(s) of the message.
677
+ ///
678
+ /// Corresponds to setting `msg_iov` and `msg_iovlen` on Unix and `lpBuffers`
679
+ /// and `dwBufferCount` on Windows.
680
+ pub fn with_buffers ( mut self , bufs : & ' bufs mut [ MaybeUninitSlice < ' bufs > ] ) -> Self {
681
+ sys:: set_msghdr_iov ( & mut self . inner , bufs. as_mut_ptr ( ) . cast ( ) , bufs. len ( ) ) ;
682
+ self
683
+ }
684
+
685
+ /// Set the mutable control buffer of the message.
686
+ ///
687
+ /// Corresponds to setting `msg_control` and `msg_controllen` on Unix and
688
+ /// `Control` on Windows.
689
+ pub fn with_control ( mut self , buf : & ' control mut [ MaybeUninit < u8 > ] ) -> Self {
690
+ sys:: set_msghdr_control ( & mut self . inner , buf. as_mut_ptr ( ) . cast ( ) , buf. len ( ) ) ;
691
+ self
692
+ }
693
+
694
+ /// Returns the flags of the message.
695
+ pub fn flags ( & self ) -> RecvFlags {
696
+ sys:: msghdr_flags ( & self . inner )
697
+ }
698
+ }
699
+
700
+ #[ cfg( not( target_os = "redox" ) ) ]
701
+ impl < ' name , ' bufs , ' control > fmt:: Debug for MsgHdrMut < ' name , ' bufs , ' control > {
702
+ fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
703
+ "MsgHdrMut" . fmt ( fmt)
704
+ }
705
+ }
0 commit comments