@@ -783,7 +783,7 @@ pub fn sendmsg(fd: RawFd, iov: &[IoVec<&[u8]>], cmsgs: &[ControlMessage],
783
783
// because subsequent code will not clear the padding bytes.
784
784
let mut cmsg_buffer = vec ! [ 0u8 ; capacity] ;
785
785
786
- unsafe { send_pack_mhdr ( mhdr. as_mut_ptr ( ) , & mut cmsg_buffer[ ..] , & iov, & cmsgs, addr) } ;
786
+ pack_mhdr ( mhdr. as_mut_ptr ( ) , & mut cmsg_buffer[ ..] , & iov, & cmsgs, addr) ;
787
787
788
788
let mhdr = unsafe { mhdr. assume_init ( ) } ;
789
789
@@ -805,9 +805,9 @@ pub struct SendMmsgData<'a, I, C>
805
805
pub _lt : std:: marker:: PhantomData < & ' a I > ,
806
806
}
807
807
808
- /// An extension of `sendmsg`` that allows the caller to transmit multiple
808
+ /// An extension of [ `sendmsg`] that allows the caller to transmit multiple
809
809
/// messages on a socket using a single system call. (This has performance
810
- /// benefits for some applications.). Supported on Linux and FreeBSD
810
+ /// benefits for some applications.).
811
811
///
812
812
/// Allocations are performed for cmsgs and to build `msghdr` buffer
813
813
///
@@ -817,11 +817,23 @@ pub struct SendMmsgData<'a, I, C>
817
817
/// * `data`: Struct that implements `IntoIterator` with `SendMmsgData` items
818
818
/// * `flags`: Optional flags passed directly to the operating system.
819
819
///
820
- /// # References
821
- /// [sendmmsg(2)](http://man7.org/linux/man-pages/man2/sendmmsg.2.html)
822
- #[ cfg( any( target_os = "linux" , target_os = "freebsd" ) ) ]
823
- pub fn sendmmsg < ' a , I , C > ( fd : RawFd , data : impl std:: iter:: IntoIterator < Item =& ' a SendMmsgData < ' a , I , C > > , flags : MsgFlags )
824
- -> Result < ( usize , Vec < usize > ) >
820
+ /// Returns tuple, where the first value is number of sent messages, and the second one
821
+ /// it a `Vec` with numbers of bytes sent on each appropriate message.
822
+ ///
823
+ ///# References
824
+ /// [`sendmmsg`](fn.sendmsg.html)
825
+ #[ cfg( any(
826
+ target_os = "linux" ,
827
+ target_os = "android" ,
828
+ target_os = "freebsd" ,
829
+ target_os = "openbsd" ,
830
+ target_os = "netbsd" ,
831
+ ) ) ]
832
+ pub fn sendmmsg < ' a , I , C > (
833
+ fd : RawFd ,
834
+ data : impl std:: iter:: IntoIterator < Item =& ' a SendMmsgData < ' a , I , C > > ,
835
+ flags : MsgFlags
836
+ ) -> Result < ( usize , Vec < usize > ) >
825
837
where
826
838
I : AsRef < [ IoVec < & ' a [ u8 ] > ] > + ' a ,
827
839
C : AsRef < [ ControlMessage < ' a > ] > + ' a ,
@@ -848,7 +860,7 @@ pub fn sendmmsg<'a, I, C>(fd: RawFd, data: impl std::iter::IntoIterator<Item=&'a
848
860
cmsgs_buffer. resize ( cmsgs_buffer_need_capacity, 0 ) ;
849
861
850
862
unsafe {
851
- send_pack_mhdr (
863
+ pack_mhdr (
852
864
& mut ( * element. as_mut_ptr ( ) ) . msg_hdr ,
853
865
& mut cmsgs_buffer[ cmsgs_start..] ,
854
866
& d. iov ,
@@ -884,7 +896,7 @@ pub struct RecvMmsgData<'a, I>
884
896
pub cmsg_buffer : Option < & ' a mut Vec < u8 > > ,
885
897
}
886
898
887
- /// An extension of recvmsg(2) that allows the caller to receive multiple
899
+ /// An extension of [` recvmsg`] that allows the caller to receive multiple
888
900
/// messages from a socket using a single system call. (This has
889
901
/// performance benefits for some applications.)
890
902
///
@@ -905,8 +917,13 @@ pub struct RecvMmsgData<'a, I>
905
917
/// [`cmsg_space!`](macro.cmsg_space.html)
906
918
///
907
919
/// # References
908
- /// [recvmmsg(2)](http://man7.org/linux/man-pages/man2/recvmmsg.2.html)
909
- #[ cfg( any( target_os = "linux" , target_os = "freebsd" ) ) ]
920
+ /// [`recvmsg`](fn.recvmsg.html)
921
+ #[ cfg( any(
922
+ target_os = "linux" ,
923
+ target_os = "android" ,
924
+ target_os = "freebsd" ,
925
+ target_os = "netbsd" ,
926
+ ) ) ]
910
927
pub fn recvmmsg < ' a , I > (
911
928
fd : RawFd ,
912
929
data : impl std:: iter:: IntoIterator < Item =& ' a mut RecvMmsgData < ' a , I > > ,
@@ -1034,7 +1051,7 @@ unsafe fn recv_pack_mhdr<'a, I>(
1034
1051
}
1035
1052
1036
1053
1037
- unsafe fn send_pack_mhdr < ' a , I , C > (
1054
+ fn pack_mhdr < ' a , I , C > (
1038
1055
out : * mut msghdr ,
1039
1056
cmsg_buffer : & mut [ u8 ] ,
1040
1057
iov : I ,
@@ -1050,7 +1067,7 @@ unsafe fn send_pack_mhdr<'a, I, C>(
1050
1067
// Next encode the sending address, if provided
1051
1068
let ( name, namelen) = match addr {
1052
1069
Some ( addr) => {
1053
- let ( x, y) = addr. as_ffi_pair ( ) ;
1070
+ let ( x, y) = unsafe { addr. as_ffi_pair ( ) } ;
1054
1071
( x as * const _ , y)
1055
1072
} ,
1056
1073
None => ( ptr:: null ( ) , 0 ) ,
@@ -1065,27 +1082,31 @@ unsafe fn send_pack_mhdr<'a, I, C>(
1065
1082
1066
1083
// Musl's msghdr has private fields, so this is the only way to
1067
1084
// initialize it.
1068
- ( * out) . msg_name = name as * mut _ ;
1069
- ( * out) . msg_namelen = namelen;
1070
- // transmute iov into a mutable pointer. sendmsg doesn't really mutate
1071
- // the buffer, but the standard says that it takes a mutable pointer
1072
- ( * out) . msg_iov = iov. as_ref ( ) . as_ptr ( ) as * mut _ ;
1073
- ( * out) . msg_iovlen = iov. as_ref ( ) . len ( ) as _ ;
1074
- ( * out) . msg_control = cmsg_ptr;
1075
- ( * out) . msg_controllen = cmsg_capacity as _ ;
1076
- ( * out) . msg_flags = 0 ;
1085
+ {
1086
+ let mut hdr = unsafe { & mut * out } ;
1087
+
1088
+ hdr. msg_name = name as * mut _ ;
1089
+ hdr. msg_namelen = namelen;
1090
+ // transmute iov into a mutable pointer. sendmsg doesn't really mutate
1091
+ // the buffer, but the standard says that it takes a mutable pointer
1092
+ hdr. msg_iov = iov. as_ref ( ) . as_ptr ( ) as * mut _ ;
1093
+ hdr. msg_iovlen = iov. as_ref ( ) . len ( ) as _ ;
1094
+ hdr. msg_control = cmsg_ptr;
1095
+ hdr. msg_controllen = cmsg_capacity as _ ;
1096
+ hdr. msg_flags = 0 ;
1097
+ }
1077
1098
1078
1099
// Encode each cmsg. This must happen after initializing the header because
1079
1100
// CMSG_NEXT_HDR and friends read the msg_control and msg_controllen fields.
1080
1101
// CMSG_FIRSTHDR is always safe
1081
- let mut pmhdr: * mut cmsghdr = CMSG_FIRSTHDR ( out) ;
1102
+ let mut pmhdr: * mut cmsghdr = unsafe { CMSG_FIRSTHDR ( out) } ;
1082
1103
for cmsg in cmsgs. as_ref ( ) {
1083
1104
assert_ne ! ( pmhdr, ptr:: null_mut( ) ) ;
1084
1105
// Safe because we know that pmhdr is valid, and we initialized it with
1085
1106
// sufficient space
1086
- cmsg. encode_into ( pmhdr) ;
1107
+ unsafe { cmsg. encode_into ( pmhdr) ; }
1087
1108
// Safe because mhdr is valid
1088
- pmhdr = CMSG_NXTHDR ( out, pmhdr) ;
1109
+ pmhdr = unsafe { CMSG_NXTHDR ( out, pmhdr) } ;
1089
1110
}
1090
1111
}
1091
1112
0 commit comments