Struct tokio_seqpacket::ancillary::AncillaryMessageReader
source · 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>
impl<'a> AncillaryMessageReader<'a>
sourcepub unsafe fn new(buffer: &'a mut [u8], truncated: bool) -> Self
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.
sourcepub fn is_truncated(&self) -> bool
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(())
}
sourcepub fn messages(&self) -> AncillaryMessages<'_> ⓘ
pub fn messages(&self) -> AncillaryMessages<'_> ⓘ
Returns the iterator of the control messages.
sourcepub fn into_messages(self) -> IntoAncillaryMessages<'a> ⓘ
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>
impl<'a> Debug for AncillaryMessageReader<'a>
Auto Trait Implementations§
impl<'a> RefUnwindSafe for AncillaryMessageReader<'a>
impl<'a> Send for AncillaryMessageReader<'a>
impl<'a> Sync for AncillaryMessageReader<'a>
impl<'a> Unpin for AncillaryMessageReader<'a>
impl<'a> !UnwindSafe for AncillaryMessageReader<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more