Struct creusot_contracts::std::os::unix::net::SocketAncillary
source · pub struct SocketAncillary<'a> { /* private fields */ }
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§
source§impl<'a> SocketAncillary<'a>
impl<'a> SocketAncillary<'a>
sourcepub fn new(buffer: &'a mut [u8]) -> SocketAncillary<'a>
🔬This is a nightly-only experimental API. (unix_socket_ancillary_data
)
pub fn new(buffer: &'a mut [u8]) -> SocketAncillary<'a>
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[..]);
sourcepub fn capacity(&self) -> usize
🔬This is a nightly-only experimental API. (unix_socket_ancillary_data
)
pub fn capacity(&self) -> usize
unix_socket_ancillary_data
)Returns the capacity of the buffer.
sourcepub fn is_empty(&self) -> bool
🔬This is a nightly-only experimental API. (unix_socket_ancillary_data
)
pub fn is_empty(&self) -> bool
unix_socket_ancillary_data
)Returns true
if the ancillary data is empty.
sourcepub fn len(&self) -> usize
🔬This is a nightly-only experimental API. (unix_socket_ancillary_data
)
pub fn len(&self) -> usize
unix_socket_ancillary_data
)Returns the number of used bytes.
sourcepub fn messages(&self) -> Messages<'_> ⓘ
🔬This is a nightly-only experimental API. (unix_socket_ancillary_data
)
pub fn messages(&self) -> Messages<'_> ⓘ
unix_socket_ancillary_data
)Returns the iterator of the control messages.
sourcepub fn truncated(&self) -> bool
🔬This is a nightly-only experimental API. (unix_socket_ancillary_data
)
pub fn truncated(&self) -> bool
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(())
}
sourcepub fn add_fds(&mut self, fds: &[i32]) -> bool
🔬This is a nightly-only experimental API. (unix_socket_ancillary_data
)
pub fn add_fds(&mut self, fds: &[i32]) -> bool
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 buf = [1; 8];
let mut bufs = &mut [IoSlice::new(&buf[..])][..];
sock.send_vectored_with_ancillary(bufs, &mut ancillary)?;
Ok(())
}
sourcepub fn add_creds(&mut self, creds: &[SocketCred]) -> bool
🔬This is a nightly-only experimental API. (unix_socket_ancillary_data
)
pub fn add_creds(&mut self, creds: &[SocketCred]) -> bool
unix_socket_ancillary_data
)Add credentials to the ancillary data.
The function returns true
if there is enough space in the buffer.
If there is not enough space then no credentials will be appended.
Technically, that means this operation adds a control message with the level SOL_SOCKET
and type SCM_CREDENTIALS
, SCM_CREDS
, or SCM_CREDS2
.
sourcepub fn clear(&mut self)
🔬This is a nightly-only experimental API. (unix_socket_ancillary_data
)
pub fn clear(&mut self)
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> Freeze for SocketAncillary<'a>
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§
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
source§impl<T> MakeSized for Twhere
T: ?Sized,
impl<T> MakeSized for Twhere
T: ?Sized,
source§fn make_sized(&self) -> Box<T>
fn make_sized(&self) -> Box<T>
logic ⚠
ensures
*result == *self