pub fn send_message_with_payload<T: Sized>(
        &mut self,
        hdr: &MsgHeader,
        body: &T,
        payload: &[u8],
        fds: Option<&[RawFd]>,
    ) -> Result<()> {
        let len = payload.len();
        if mem::size_of::<T>() > MAX_MSG_SIZE {
            return Err(Error::OversizedMsg);
        }
        if len > MAX_MSG_SIZE - mem::size_of::<T>() {
            return Err(Error::OversizedMsg);
        }
        if let Some(fd_arr) = fds {
            if fd_arr.len() > MAX_ATTACHED_FD_ENTRIES {
                return Err(Error::IncorrectFds);
            }
        }

        // Safe because there can't be other mutable reference to hdr, body and payload.
        let iovs = unsafe {
            [
                slice::from_raw_parts(
                    hdr as *const MsgHeader as *const u8,
                    mem::size_of::<MsgHeader>(),
                ),
                slice::from_raw_parts(body as *const T as *const u8, mem::size_of::<T>()),
                slice::from_raw_parts(payload.as_ptr() as *const u8, len),
            ]
        };
        let total = mem::size_of::<MsgHeader>() + mem::size_of::<T>() + len;
        let len = self.send_iovec_all(&iovs, fds)?;
        if len != total {
            return Err(Error::PartialMessage);
        }
        Ok(())
    }
/// Send a message with header, body and payload. Optional file descriptors
/// may also be attached to the message.
///
/// # Return:
/// * - number of bytes sent on success
/// * - SocketRetry: temporary error caused by signals or short of resources.
/// * - SocketBroken: the underline socket is broken.
/// * - SocketError: other socket related errors.
/// * - OversizedMsg: message size is too big.
/// * - PartialMessage: received a partial message.
/// * - IncorrectFds: wrong number of attached fds.
Send a message with header, body and payload. Optional file descriptors
may also be attached to the message.
Send a message with header body and payload . Optional file descriptors may also be attached to the message .
pub fn send_message_with_payload<T: Sized>(
        &mut self,
        hdr: &MsgHeader,
        body: &T,
        payload: &[u8],
        fds: Option<&[RawFd]>,
    ) -> Result<()> {
        let len = payload.len();
        if mem::size_of::<T>() > MAX_MSG_SIZE {
            return Err(Error::OversizedMsg);
        }
        if len > MAX_MSG_SIZE - mem::size_of::<T>() {
            return Err(Error::OversizedMsg);
        }
        if let Some(fd_arr) = fds {
            if fd_arr.len() > MAX_ATTACHED_FD_ENTRIES {
                return Err(Error::IncorrectFds);
            }
        }
        // Safe because there can't be other mutable reference to hdr, body and payload.
        let iovs = unsafe {
            [
                slice::from_raw_parts(
                    hdr as *const MsgHeader as *const u8,
                    mem::size_of::<MsgHeader>(),
                ),
                slice::from_raw_parts(body as *const T as *const u8, mem::size_of::<T>()),
                slice::from_raw_parts(payload.as_ptr() as *const u8, len),
            ]
        };
        let total = mem::size_of::<MsgHeader>() + mem::size_of::<T>() + len;
        let len = self.send_iovec_all(&iovs, fds)?;
        if len != total {
            return Err(Error::PartialMessage);
        }
        Ok(())
    }
pub fn send_message_with_payload < T : Sized > ( & mut self , hdr : & MsgHeader , body : & T , payload : & [ u8 ] , fds : Option < & [ RawFd ] > , ) -> Result < ( ) > { let len = payload . len ( ) ; if mem :: size_of :: < T > ( ) > MAX_MSG_SIZE { return Err ( Error :: OversizedMsg ) ; } if len > MAX_MSG_SIZE - mem :: size_of :: < T > ( ) { return Err ( Error :: OversizedMsg ) ; } if let Some ( fd_arr ) = fds { if fd_arr . len ( ) > MAX_ATTACHED_FD_ENTRIES { return Err ( Error :: IncorrectFds ) ; } } // Safe because there can't be other mutable reference to hdr, body and payload. let iovs = unsafe { [ slice :: from_raw_parts ( hdr as * const MsgHeader as * const u8 , mem :: size_of :: < MsgHeader > ( ) , ) , slice :: from_raw_parts ( body as * const T as * const u8 , mem :: size_of :: < T > ( ) ) , slice :: from_raw_parts ( payload . as_ptr ( ) as * const u8 , len ) , ] } ; let total = mem :: size_of :: < MsgHeader > ( ) + mem :: size_of :: < T > ( ) + len ; let len = self . send_iovec_all ( & iovs , fds ) ? ; if len != total { return Err ( Error :: PartialMessage ) ; } Ok ( ( ) ) }
Send a message with header, body and payload.
Send a message with header body and payload .
&mut self
hdr
&MsgHeader
body
&T
payload
&[u8]
fds
Option<&[RawFd]>
&mut self
hdr
&MsgHeader
body
&T
payload
&[u8]
fds
Option<&[RawFd]>
return:
- number of bytes sent on success
- SocketRetry: temporary error caused by signals or short of resources.
- SocketBroken: the underline socket is broken.
- SocketError: other socket related errors.
- OversizedMsg: message size is too big.
- PartialMessage: received a partial message.
- IncorrectFds: wrong number of attached fds.
- number of bytes sent on success - SocketRetry : temporary error caused by signals or short of resources . - SocketBroken : the underline socket is broken . - SocketError : other socket related errors . - OversizedMsg : message size is too big . - PartialMessage : received a partial message . - IncorrectFds : wrong number of attached fds .