pub fn send_message<T: Sized>(
        &mut self,
        hdr: &MsgHeader,
        body: &T,
        fds: Option<&[RawFd]>,
    ) -> Result<()> {
        if mem::size_of::<T>() > MAX_MSG_SIZE {
            return Err(Error::OversizedMsg);
        }
        // Safe because there can't be other mutable referance to hdr and body.
        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>()),
            ]
        };
        let bytes = self.send_iovec_all(&iovs[..], fds)?;
        if bytes != mem::size_of::<MsgHeader>() + mem::size_of::<T>() {
            return Err(Error::PartialMessage);
        }
        Ok(())
    }
/// Send a message with header and body. Optional file descriptors may 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.
/// * - PartialMessage: received a partial message.
Send a message with header and body. Optional file descriptors may be attached to
the message.
Send a message with header and body . Optional file descriptors may be attached to the message .
pub fn send_message<T: Sized>(
        &mut self,
        hdr: &MsgHeader,
        body: &T,
        fds: Option<&[RawFd]>,
    ) -> Result<()> {
        if mem::size_of::<T>() > MAX_MSG_SIZE {
            return Err(Error::OversizedMsg);
        }
        // Safe because there can't be other mutable referance to hdr and body.
        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>()),
            ]
        };
        let bytes = self.send_iovec_all(&iovs[..], fds)?;
        if bytes != mem::size_of::<MsgHeader>() + mem::size_of::<T>() {
            return Err(Error::PartialMessage);
        }
        Ok(())
    }
pub fn send_message < T : Sized > ( & mut self , hdr : & MsgHeader , body : & T , fds : Option < & [ RawFd ] > , ) -> Result < ( ) > { if mem :: size_of :: < T > ( ) > MAX_MSG_SIZE { return Err ( Error :: OversizedMsg ) ; } // Safe because there can't be other mutable referance to hdr and body. 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 > ( ) ) , ] } ; let bytes = self . send_iovec_all ( & iovs [ .. ] , fds ) ? ; if bytes != mem :: size_of :: < MsgHeader > ( ) + mem :: size_of :: < T > ( ) { return Err ( Error :: PartialMessage ) ; } Ok ( ( ) ) }
Send a message with header and body.
Send a message with header and body .
&mut self
hdr
&MsgHeader
body
&T
fds
Option<&[RawFd]>
&mut self
hdr
&MsgHeader
body
&T
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.
- PartialMessage: received a partial message.
- 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 . - PartialMessage : received a partial message .