@@ -701,3 +701,202 @@ impl<'name, 'bufs, 'control> fmt::Debug for MsgHdrMut<'name, 'bufs, 'control> {
701
701
"MsgHdrMut" . fmt ( fmt)
702
702
}
703
703
}
704
+
705
+ /// Configuration of a `sendmmsg(2)` system call.
706
+ ///
707
+ /// This wraps `mmsghdr` on Unix. Also see [`MMsgHdrMut`] for the variant used by `recvmmsg(2)`.
708
+ /// This API is not available on Windows.
709
+ #[ cfg( any(
710
+ target_os = "aix" ,
711
+ target_os = "android" ,
712
+ target_os = "freebsd" ,
713
+ target_os = "linux" ,
714
+ target_os = "netbsd" ,
715
+ target_os = "openbsd" ,
716
+ ) ) ]
717
+ pub struct MMsgHdr < ' addr , ' bufs , ' control > {
718
+ inner : sys:: mmsghdr ,
719
+ #[ allow( clippy:: type_complexity) ]
720
+ _lifetimes : PhantomData < ( & ' addr SockAddr , & ' bufs IoSlice < ' bufs > , & ' control [ u8 ] ) > ,
721
+ }
722
+
723
+ #[ cfg( any(
724
+ target_os = "aix" ,
725
+ target_os = "android" ,
726
+ target_os = "freebsd" ,
727
+ target_os = "linux" ,
728
+ target_os = "netbsd" ,
729
+ target_os = "openbsd" ,
730
+ ) ) ]
731
+ impl < ' addr , ' bufs , ' control > MMsgHdr < ' addr , ' bufs , ' control > {
732
+ /// Create a new `MMsgHdr` with all empty/zero fields.
733
+ #[ allow( clippy:: new_without_default) ]
734
+ pub fn new ( ) -> MMsgHdr < ' addr , ' bufs , ' control > {
735
+ // SAFETY: all zero is valid for `mmsghdr`.
736
+ MMsgHdr {
737
+ inner : unsafe { mem:: zeroed ( ) } ,
738
+ _lifetimes : PhantomData ,
739
+ }
740
+ }
741
+
742
+ /// Set the address (name) of the message.
743
+ ///
744
+ /// Corresponds to setting `msg_name` and `msg_namelen` on Unix.
745
+ pub fn with_addr ( mut self , addr : & ' addr SockAddr ) -> Self {
746
+ sys:: set_msghdr_name ( & mut self . inner . msg_hdr , addr) ;
747
+ self
748
+ }
749
+
750
+ /// Set the buffer(s) of the message.
751
+ ///
752
+ /// Corresponds to setting `msg_iov` and `msg_iovlen` on Unix.
753
+ pub fn with_buffers ( mut self , bufs : & ' bufs [ IoSlice < ' _ > ] ) -> Self {
754
+ let ptr = bufs. as_ptr ( ) as * mut _ ;
755
+ sys:: set_msghdr_iov ( & mut self . inner . msg_hdr , ptr, bufs. len ( ) ) ;
756
+ self
757
+ }
758
+
759
+ /// Set the control buffer of the message.
760
+ ///
761
+ /// Corresponds to setting `msg_control` and `msg_controllen` on Unix.
762
+ pub fn with_control ( mut self , buf : & ' control [ u8 ] ) -> Self {
763
+ let ptr = buf. as_ptr ( ) as * mut _ ;
764
+ sys:: set_msghdr_control ( & mut self . inner . msg_hdr , ptr, buf. len ( ) ) ;
765
+ self
766
+ }
767
+
768
+ /// Set the flags of the message.
769
+ ///
770
+ /// Corresponds to setting `msg_flags` on Unix.
771
+ pub fn with_flags ( mut self , flags : sys:: c_int ) -> Self {
772
+ sys:: set_msghdr_flags ( & mut self . inner . msg_hdr , flags) ;
773
+ self
774
+ }
775
+
776
+ /// Gets the number of sent bytes.
777
+ ///
778
+ /// Corresponds to `msg_len` on Unix.
779
+ pub fn data_len ( & self ) -> usize {
780
+ self . inner . msg_len as usize
781
+ }
782
+ }
783
+
784
+ #[ cfg( any(
785
+ target_os = "aix" ,
786
+ target_os = "android" ,
787
+ target_os = "freebsd" ,
788
+ target_os = "linux" ,
789
+ target_os = "netbsd" ,
790
+ target_os = "openbsd" ,
791
+ ) ) ]
792
+ impl < ' name , ' bufs , ' control > fmt:: Debug for MMsgHdr < ' name , ' bufs , ' control > {
793
+ fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
794
+ "MMsgHdr" . fmt ( fmt)
795
+ }
796
+ }
797
+
798
+ /// Configuration of a `recvmmsg(2)` system call.
799
+ ///
800
+ /// This wraps `mmsghdr` on Unix. Also see [`MMsgHdr`] for the variant used by `sendmmsg(2)`.
801
+ /// This API is not available on Windows.
802
+ #[ cfg( any(
803
+ target_os = "aix" ,
804
+ target_os = "android" ,
805
+ target_os = "freebsd" ,
806
+ target_os = "linux" ,
807
+ target_os = "netbsd" ,
808
+ target_os = "openbsd" ,
809
+ ) ) ]
810
+ pub struct MMsgHdrMut < ' addr , ' bufs , ' control > {
811
+ inner : sys:: mmsghdr ,
812
+ #[ allow( clippy:: type_complexity) ]
813
+ _lifetimes : PhantomData < (
814
+ & ' addr mut SockAddr ,
815
+ & ' bufs mut MaybeUninitSlice < ' bufs > ,
816
+ & ' control mut [ u8 ] ,
817
+ ) > ,
818
+ }
819
+
820
+ #[ cfg( any(
821
+ target_os = "aix" ,
822
+ target_os = "android" ,
823
+ target_os = "freebsd" ,
824
+ target_os = "linux" ,
825
+ target_os = "netbsd" ,
826
+ target_os = "openbsd" ,
827
+ ) ) ]
828
+ impl < ' addr , ' bufs , ' control > MMsgHdrMut < ' addr , ' bufs , ' control > {
829
+ /// Create a new `MMsgHdrMut` with all empty/zero fields.
830
+ #[ allow( clippy:: new_without_default) ]
831
+ pub fn new ( ) -> MMsgHdrMut < ' addr , ' bufs , ' control > {
832
+ // SAFETY: all zero is valid for `mmsghdr`.
833
+ MMsgHdrMut {
834
+ inner : unsafe { mem:: zeroed ( ) } ,
835
+ _lifetimes : PhantomData ,
836
+ }
837
+ }
838
+
839
+ /// Set the mutable address (name) of the message.
840
+ ///
841
+ /// Corresponds to setting `msg_name` and `msg_namelen` on Unix.
842
+ #[ allow( clippy:: needless_pass_by_ref_mut) ]
843
+ pub fn with_addr ( mut self , addr : & ' addr mut SockAddr ) -> Self {
844
+ sys:: set_msghdr_name ( & mut self . inner . msg_hdr , addr) ;
845
+ self
846
+ }
847
+
848
+ /// Set the mutable buffer(s) of the message.
849
+ ///
850
+ /// Corresponds to setting `msg_iov` and `msg_iovlen` on Unix.
851
+ pub fn with_buffers ( mut self , bufs : & ' bufs mut [ MaybeUninitSlice < ' _ > ] ) -> Self {
852
+ sys:: set_msghdr_iov (
853
+ & mut self . inner . msg_hdr ,
854
+ bufs. as_mut_ptr ( ) . cast ( ) ,
855
+ bufs. len ( ) ,
856
+ ) ;
857
+ self
858
+ }
859
+
860
+ /// Set the mutable control buffer of the message.
861
+ ///
862
+ /// Corresponds to setting `msg_control` and `msg_controllen` on Unix.
863
+ pub fn with_control ( mut self , buf : & ' control mut [ MaybeUninit < u8 > ] ) -> Self {
864
+ sys:: set_msghdr_control ( & mut self . inner . msg_hdr , buf. as_mut_ptr ( ) . cast ( ) , buf. len ( ) ) ;
865
+ self
866
+ }
867
+
868
+ /// Returns the flags of the message.
869
+ pub fn flags ( & self ) -> RecvFlags {
870
+ sys:: msghdr_flags ( & self . inner . msg_hdr )
871
+ }
872
+
873
+ /// Gets the length of the control buffer.
874
+ ///
875
+ /// Can be used to determine how much, if any, of the control buffer was filled by `recvmsg`.
876
+ ///
877
+ /// Corresponds to `msg_controllen` on Unix.
878
+ pub fn control_len ( & self ) -> usize {
879
+ sys:: msghdr_control_len ( & self . inner . msg_hdr )
880
+ }
881
+
882
+ /// Gets the number of received bytes.
883
+ ///
884
+ /// Corresponds to `msg_len` on Unix.
885
+ pub fn data_len ( & self ) -> usize {
886
+ self . inner . msg_len as usize
887
+ }
888
+ }
889
+
890
+ #[ cfg( any(
891
+ target_os = "aix" ,
892
+ target_os = "android" ,
893
+ target_os = "freebsd" ,
894
+ target_os = "linux" ,
895
+ target_os = "netbsd" ,
896
+ target_os = "openbsd" ,
897
+ ) ) ]
898
+ impl < ' name , ' bufs , ' control > fmt:: Debug for MMsgHdrMut < ' name , ' bufs , ' control > {
899
+ fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
900
+ "MMsgHdrMut" . fmt ( fmt)
901
+ }
902
+ }
0 commit comments