doc additions

This commit is contained in:
David Carlier 2022-04-27 06:01:05 +01:00
parent 14d288fe12
commit 48ef00e36f
3 changed files with 38 additions and 1 deletions

View file

@ -838,6 +838,25 @@ impl UnixDatagram {
self.0.passcred()
}
/// Set the id of the socket for network filtering purpose
/// and is only a setter.
///
/// ```no_run
/// #![feature(unix_set_mark)]
/// use std::os::unix::net::UnixDatagram;
///
/// fn main() -> std::io::Result<()> {
/// let sock = UnixDatagram::unbound()?;
/// sock.set_mark(32 as u32).expect("set_mark function failed");
/// Ok(())
/// }
/// ```
#[cfg(any(doc, target_os = "linux", target_os = "freebsd", target_os = "openbsd",))]
#[unstable(feature = "unix_set_mark", issue = "none")]
pub fn set_mark(&self, mark: u32) -> io::Result<()> {
self.0.set_mark(mark)
}
/// Returns the value of the `SO_ERROR` option.
///
/// # Examples

View file

@ -424,7 +424,20 @@ impl UnixStream {
self.0.passcred()
}
#[cfg(any(doc, target_os = "linux", target_os = "freebsd",))]
/// Set the id of the socket for network filtering purpose
/// and is only a setter.
///
/// ```no_run
/// #![feature(unix_set_mark)]
/// use std::os::unix::net::UnixStream;
///
/// fn main() -> std::io::Result<()> {
/// let sock = UnixStream::connect("/tmp/sock")?;
/// sock.set_mark(32 as u32).expect("set_mark function failed");
/// Ok(())
/// }
/// ```
#[cfg(any(doc, target_os = "linux", target_os = "freebsd", target_os = "openbsd",))]
#[unstable(feature = "unix_set_mark", issue = "none")]
pub fn set_mark(&self, mark: u32) -> io::Result<()> {
self.0.set_mark(mark)

View file

@ -437,6 +437,11 @@ impl Socket {
setsockopt(self, libc::SOL_SOCKET, libc::SO_USER_COOKIE, mark)
}
#[cfg(target_os = "openbsd")]
pub fn set_mark(&self, mark: u32) -> io::Result<()> {
setsockopt(self, libc::SOL_SOCKET, libc::SO_RTABLE, mark as libc::c_int)
}
pub fn take_error(&self) -> io::Result<Option<io::Error>> {
let raw: c_int = getsockopt(self, libc::SOL_SOCKET, libc::SO_ERROR)?;
if raw == 0 { Ok(None) } else { Ok(Some(io::Error::from_raw_os_error(raw as i32))) }