Struct std::os::unix::net::SocketAncillary [−][src]
pub struct SocketAncillary<'a> { /* fields omitted */ }
This is supported on Unix only.
Expand description
Unix 套接字辅助数据结构体。
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(()) }Run
Implementations
This is supported on Android or DragonFly BSD or Emscripten or FreeBSD or Linux or NetBSD or OpenBSD only.
This is supported on Android or DragonFly BSD or Emscripten or FreeBSD or Linux or NetBSD or OpenBSD only.
This is supported on Android or DragonFly BSD or Emscripten or FreeBSD or Linux or NetBSD or OpenBSD only.
This is supported on Android or DragonFly BSD or Emscripten or FreeBSD or Linux or NetBSD or OpenBSD only.
返回缓冲区的容量。
This is supported on Android or DragonFly BSD or Emscripten or FreeBSD or Linux or NetBSD or OpenBSD only.
This is supported on Android or DragonFly BSD or Emscripten or FreeBSD or Linux or NetBSD or OpenBSD only.
如果辅助数据为空,则返回 true
。
This is supported on Android or DragonFly BSD or Emscripten or FreeBSD or Linux or NetBSD or OpenBSD only.
This is supported on Android or DragonFly BSD or Emscripten or FreeBSD or Linux or NetBSD or OpenBSD only.
返回使用的字节数。
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 supported on Android or DragonFly BSD or Emscripten or FreeBSD or Linux or NetBSD or OpenBSD only.
pub fn messages(&self) -> Messages<'_>ⓘNotable traits for Messages<'a>impl<'a> Iterator for Messages<'a> type Item = Result<AncillaryData<'a>, AncillaryError>;
[src]Notable traits for Messages<'a>
impl<'a> Iterator for Messages<'a> type Item = Result<AncillaryData<'a>, AncillaryError>;
This is supported on Android or DragonFly BSD or Emscripten or FreeBSD or Linux or NetBSD or OpenBSD only.
返回控制消息的迭代器。
This is supported on Android or DragonFly BSD or Emscripten or FreeBSD or Linux or NetBSD or OpenBSD only.
This is supported on Android or DragonFly BSD or Emscripten or FreeBSD or Linux or NetBSD or OpenBSD only.
如果在 recv 操作期间辅助设备被截断,则为 true
。
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(()) }Run
This is supported on Android or DragonFly BSD or Emscripten or FreeBSD or Linux or NetBSD or OpenBSD only.
This is supported on Android or DragonFly BSD or Emscripten or FreeBSD or Linux or NetBSD or OpenBSD only.
将文件描述符添加到辅助数据。
如果缓冲区中有足够的空间,函数将返回 true
。
如果没有足够的空间,则不会附加文件描述符。
从技术上讲,这意味着此操作将添加级别为 SOL_SOCKET
和类型 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(()) }Run
This is supported on Android or DragonFly BSD or Emscripten or FreeBSD or Linux or NetBSD or OpenBSD only.
This is supported on Android or DragonFly BSD or Emscripten or FreeBSD or Linux or NetBSD or OpenBSD only.
将凭证添加到辅助数据。
如果缓冲区中有足够的空间,函数将返回 true
。
如果没有足够的空间,则不会附加凭据。
从技术上讲,这意味着此操作将添加级别为 SOL_SOCKET
且类型为 SCM_CREDENTIALS
或 SCM_CREDS
的控制消息。
This is supported on Android or DragonFly BSD or Emscripten or FreeBSD or Linux or NetBSD or OpenBSD only.
This is supported on Android or DragonFly BSD or Emscripten or FreeBSD or Linux or NetBSD or OpenBSD only.
清除辅助数据,删除所有值。
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(()) }Run