doc additions
This commit is contained in:
parent
14d288fe12
commit
48ef00e36f
3 changed files with 38 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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))) }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue