/// Constructs a cmsghdr for this control data, with a destination of `task`.
///
/// The provided `task` is used to create any required file descriptors, etc.
Constructs a cmsghdr for this control data, with a destination of `task`.
The provided `task` is used to create any required file descriptors, etc.
Constructs a cmsghdr for this control data with a destination of ` task ` . The provided ` task ` is used to create any required file descriptors etc .
pub fn into_cmsghdr(self, task: &Task) -> Result<cmsghdr, Errno> {
        let mut cmsg_data = [0u8; SCM_MAX_FD * 4];
        let (cmsg_type, cmsg_len) = match self {
            UnixControlData::Rights(files) => {
                let fds: Vec<FdNumber> = files
                    .iter()
                    .map(|file| task.files.add_with_flags(file.clone(), FdFlags::empty()))
                    .collect::<Result<Vec<FdNumber>, Errno>>()?;
                let fd_bytes = fds.as_bytes();
                for (index, byte) in fd_bytes.iter().enumerate() {
                    cmsg_data[index] = *byte;
                }
                (SCM_RIGHTS, fd_bytes.len())
            }
            UnixControlData::Credentials(credentials) => {
                let bytes = credentials.as_bytes();
                for (index, byte) in bytes.iter().enumerate() {
                    cmsg_data[index] = *byte;
                }
                (SCM_CREDENTIALS, bytes.len())
            }
            UnixControlData::Security(string) => {
                for (index, byte) in string.iter().enumerate() {
                    cmsg_data[index] = *byte;
                }
                (SCM_SECURITY, string.len())
            }
        };
        Ok(cmsghdr {
            cmsg_len: cmsg_len + cmsghdr::header_length(),
            cmsg_level: SOL_SOCKET,
            cmsg_type,
            cmsg_data,
        })
    }
pub fn into_cmsghdr ( self , task : & Task ) -> Result < cmsghdr , Errno > { let mut cmsg_data = [ 0u8 ; SCM_MAX_FD * 4 ] ; let ( cmsg_type , cmsg_len ) = match self { UnixControlData :: Rights ( files ) => { let fds : Vec < FdNumber > = files . iter ( ) . map ( | file | task . files . add_with_flags ( file . clone ( ) , FdFlags :: empty ( ) ) ) . collect :: < Result < Vec < FdNumber > , Errno > > ( ) ? ; let fd_bytes = fds . as_bytes ( ) ; for ( index , byte ) in fd_bytes . iter ( ) . enumerate ( ) { cmsg_data [ index ] = * byte ; } ( SCM_RIGHTS , fd_bytes . len ( ) ) } UnixControlData :: Credentials ( credentials ) => { let bytes = credentials . as_bytes ( ) ; for ( index , byte ) in bytes . iter ( ) . enumerate ( ) { cmsg_data [ index ] = * byte ; } ( SCM_CREDENTIALS , bytes . len ( ) ) } UnixControlData :: Security ( string ) => { for ( index , byte ) in string . iter ( ) . enumerate ( ) { cmsg_data [ index ] = * byte ; } ( SCM_SECURITY , string . len ( ) ) } } ; Ok ( cmsghdr { cmsg_len : cmsg_len + cmsghdr :: header_length ( ) , cmsg_level : SOL_SOCKET , cmsg_type , cmsg_data , } ) }
Constructs a cmsghdr for this control data, with a destination of `task`.
Constructs a cmsghdr for this control data with a destination of ` task ` .
self
task
&Task