pub struct AncillaryMessageReader<'a> { /* private fields */ }
Expand description

Reader to parse received ancillary messages from a Unix socket.

Example

use tokio_seqpacket::UnixSeqpacket;
use tokio_seqpacket::ancillary::{AncillaryMessageReader, AncillaryMessage};
use std::io::IoSliceMut;
use std::os::fd::AsRawFd;

#[tokio::main]
async fn main() -> std::io::Result<()> {
    let sock = UnixSeqpacket::connect("/tmp/sock").await?;

    let mut fds = [0; 8];
    let mut ancillary_buffer = [0; 128];

    let mut buf = [1; 8];
    let mut bufs = [IoSliceMut::new(&mut buf)];
    let (_read, ancillary) = sock.recv_vectored_with_ancillary(&mut bufs, &mut ancillary_buffer).await?;

    for message in ancillary.messages() {
        if let AncillaryMessage::FileDescriptors(fds) = message {
            for fd in fds {
                println!("received file descriptor: {}", fd.as_raw_fd());
            }
        }
    }
    Ok(())
}

Implementations§

source§

impl<'a> AncillaryMessageReader<'a>

source

pub unsafe fn new(buffer: &'a mut [u8], truncated: bool) -> Self

Create an ancillary data with the given buffer.

Safety

The memory buffer must contain valid ancillary messages received from the kernel for a Unix socket.

The created reader assumes ownership of objects (such as file descriptors) within the message. Because of this, you may only create one ancillary message reader for any ancillary message received from the kernel. You must also ensure that no other object assumes ownership of the objects within the message.

source

pub fn len(&self) -> usize

Returns the number of used bytes.

source

pub fn is_empty(&self) -> bool

Returns true if the ancillary data is empty.

source

pub fn is_truncated(&self) -> bool

Is true if during a recv operation the ancillary message was truncated.

Example
use tokio_seqpacket::UnixSeqpacket;
use tokio_seqpacket::ancillary::AncillaryMessageReader;
use std::io::IoSliceMut;

#[tokio::main]
async fn main() -> std::io::Result<()> {
    let sock = UnixSeqpacket::connect("/tmp/sock").await?;

    let mut ancillary_buffer = [0; 128];

    let mut buf = [1; 8];
    let mut bufs = &mut [IoSliceMut::new(&mut buf)];
    let (_read, ancillary) = sock.recv_vectored_with_ancillary(bufs, &mut ancillary_buffer).await?;

    println!("Is truncated: {}", ancillary.is_truncated());
    Ok(())
}
source

pub fn messages(&self) -> AncillaryMessages<'_>

Returns the iterator of the control messages.

source

pub fn into_messages(self) -> IntoAncillaryMessages<'a>

Consume the ancillary message to take ownership of the contained objects (such as file descriptors).

Trait Implementations§

source§

impl<'a> Debug for AncillaryMessageReader<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for AncillaryMessageReader<'_>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.