Struct otter::prelude::unix::net::SocketAncillary [−][src]
pub struct SocketAncillary<'a> { /* fields omitted */ }
unix_socket_ancillary_data
)Expand description
A Unix socket Ancillary data struct.
Example
#![feature(unix_socket_ancillary_data)] use std::os::unix::net::{UnixStream, SocketAncillary, AncillaryData}; use std::io::IoSliceMut; fn main() -> std::io::Result<()> { let sock = UnixStream::connect("/tmp/sock")?; let mut fds = [0; 8]; let mut ancillary_buffer = [0; 128]; let mut ancillary = SocketAncillary::new(&mut ancillary_buffer[..]); let mut buf = [1; 8]; let mut bufs = &mut [IoSliceMut::new(&mut buf[..])][..]; sock.recv_vectored_with_ancillary(bufs, &mut ancillary)?; for ancillary_result in ancillary.messages() { if let AncillaryData::ScmRights(scm_rights) = ancillary_result.unwrap() { for fd in scm_rights { println!("receive file descriptor: {}", fd); } } } Ok(()) }
Implementations
🔬 This is a nightly-only experimental API. (unix_socket_ancillary_data
)
unix_socket_ancillary_data
)Create an ancillary data with the given buffer.
Example
#![feature(unix_socket_ancillary_data)] use std::os::unix::net::SocketAncillary; let mut ancillary_buffer = [0; 128]; let mut ancillary = SocketAncillary::new(&mut ancillary_buffer[..]);
🔬 This is a nightly-only experimental API. (unix_socket_ancillary_data
)
unix_socket_ancillary_data
)Returns the capacity of the buffer.
🔬 This is a nightly-only experimental API. (unix_socket_ancillary_data
)
unix_socket_ancillary_data
)Returns true
if the ancillary data is empty.
🔬 This is a nightly-only experimental API. (unix_socket_ancillary_data
)
unix_socket_ancillary_data
)Returns the number of used bytes.
pub fn messages(&self) -> Messages<'_>ⓘNotable traits for Messages<'a>
impl<'a> Iterator for Messages<'a> type Item = Result<AncillaryData<'a>, AncillaryError>;
[src]🔬 This is a nightly-only experimental API. (unix_socket_ancillary_data
)
pub fn messages(&self) -> Messages<'_>ⓘNotable traits for Messages<'a>
impl<'a> Iterator for Messages<'a> type Item = Result<AncillaryData<'a>, AncillaryError>;
[src]unix_socket_ancillary_data
)Returns the iterator of the control messages.
🔬 This is a nightly-only experimental API. (unix_socket_ancillary_data
)
unix_socket_ancillary_data
)Is true
if during a recv operation the ancillary was truncated.
Example
#![feature(unix_socket_ancillary_data)] use std::os::unix::net::{UnixStream, SocketAncillary}; use std::io::IoSliceMut; fn main() -> std::io::Result<()> { let sock = UnixStream::connect("/tmp/sock")?; let mut ancillary_buffer = [0; 128]; let mut ancillary = SocketAncillary::new(&mut ancillary_buffer[..]); let mut buf = [1; 8]; let mut bufs = &mut [IoSliceMut::new(&mut buf[..])][..]; sock.recv_vectored_with_ancillary(bufs, &mut ancillary)?; println!("Is truncated: {}", ancillary.truncated()); Ok(()) }
🔬 This is a nightly-only experimental API. (unix_socket_ancillary_data
)
unix_socket_ancillary_data
)Add file descriptors to the ancillary data.
The function returns true
if there was enough space in the buffer.
If there was not enough space then no file descriptors was appended.
Technically, that means this operation adds a control message with the level SOL_SOCKET
and type SCM_RIGHTS
.
Example
#![feature(unix_socket_ancillary_data)] use std::os::unix::net::{UnixStream, SocketAncillary}; use std::os::unix::io::AsRawFd; use std::io::IoSlice; fn main() -> std::io::Result<()> { let sock = UnixStream::connect("/tmp/sock")?; let mut ancillary_buffer = [0; 128]; let mut ancillary = SocketAncillary::new(&mut ancillary_buffer[..]); ancillary.add_fds(&[sock.as_raw_fd()][..]); let mut buf = [1; 8]; let mut bufs = &mut [IoSlice::new(&mut buf[..])][..]; sock.send_vectored_with_ancillary(bufs, &mut ancillary)?; Ok(()) }
🔬 This is a nightly-only experimental API. (unix_socket_ancillary_data
)
unix_socket_ancillary_data
)Add credentials to the ancillary data.
The function returns true
if there was enough space in the buffer.
If there was not enough space then no credentials was appended.
Technically, that means this operation adds a control message with the level SOL_SOCKET
and type SCM_CREDENTIALS
or SCM_CREDS
.
🔬 This is a nightly-only experimental API. (unix_socket_ancillary_data
)
unix_socket_ancillary_data
)Clears the ancillary data, removing all values.
Example
#![feature(unix_socket_ancillary_data)] use std::os::unix::net::{UnixStream, SocketAncillary, AncillaryData}; use std::io::IoSliceMut; fn main() -> std::io::Result<()> { let sock = UnixStream::connect("/tmp/sock")?; let mut fds1 = [0; 8]; let mut fds2 = [0; 8]; let mut ancillary_buffer = [0; 128]; let mut ancillary = SocketAncillary::new(&mut ancillary_buffer[..]); let mut buf = [1; 8]; let mut bufs = &mut [IoSliceMut::new(&mut buf[..])][..]; sock.recv_vectored_with_ancillary(bufs, &mut ancillary)?; for ancillary_result in ancillary.messages() { if let AncillaryData::ScmRights(scm_rights) = ancillary_result.unwrap() { for fd in scm_rights { println!("receive file descriptor: {}", fd); } } } ancillary.clear(); sock.recv_vectored_with_ancillary(bufs, &mut ancillary)?; for ancillary_result in ancillary.messages() { if let AncillaryData::ScmRights(scm_rights) = ancillary_result.unwrap() { for fd in scm_rights { println!("receive file descriptor: {}", fd); } } } Ok(()) }
Trait Implementations
Auto Trait Implementations
impl<'a> RefUnwindSafe for SocketAncillary<'a>
impl<'a> Send for SocketAncillary<'a>
impl<'a> Sync for SocketAncillary<'a>
impl<'a> Unpin for SocketAncillary<'a>
impl<'a> !UnwindSafe for SocketAncillary<'a>
Blanket Implementations
Mutably borrows from an owned value. Read more
Convert Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read more
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more
pub fn dyn_cast<T>(
self
) -> Result<<A as DynCastExtHelper<T>>::Target, <A as DynCastExtHelper<T>>::Source> where
T: ?Sized,
A: DynCastExtHelper<T>,
[src]
pub fn dyn_cast<T>(
self
) -> Result<<A as DynCastExtHelper<T>>::Target, <A as DynCastExtHelper<T>>::Source> where
T: ?Sized,
A: DynCastExtHelper<T>,
[src]Use this to cast from one trait object type to another. Read more
pub fn dyn_upcast<T>(self) -> <A as DynCastExtAdvHelper<T, T>>::Target where
T: ?Sized,
A: DynCastExtAdvHelper<T, T, Source = <A as DynCastExtAdvHelper<T, T>>::Target>,
[src]
pub fn dyn_upcast<T>(self) -> <A as DynCastExtAdvHelper<T, T>>::Target where
T: ?Sized,
A: DynCastExtAdvHelper<T, T, Source = <A as DynCastExtAdvHelper<T, T>>::Target>,
[src]Use this to upcast a trait to one of its supertraits. Read more
pub fn dyn_cast_adv<F, T>(
self
) -> Result<<A as DynCastExtAdvHelper<F, T>>::Target, <A as DynCastExtAdvHelper<F, T>>::Source> where
F: ?Sized,
T: ?Sized,
A: DynCastExtAdvHelper<F, T>,
[src]
pub fn dyn_cast_adv<F, T>(
self
) -> Result<<A as DynCastExtAdvHelper<F, T>>::Target, <A as DynCastExtAdvHelper<F, T>>::Source> where
F: ?Sized,
T: ?Sized,
A: DynCastExtAdvHelper<F, T>,
[src]pub fn dyn_cast_with_config<C>(
self
) -> Result<<A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Target, <A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Source> where
C: DynCastConfig,
A: DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>,
[src]
pub fn dyn_cast_with_config<C>(
self
) -> Result<<A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Target, <A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Source> where
C: DynCastConfig,
A: DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>,
[src]Use this to cast from one trait object type to another. With this method the type parameter is a config type that uniquely specifies which cast should be preformed. Read more
type Output = T
type Output = T
Should always be Self
pub fn vzip(self) -> V