diff options
| author | David Carlier <devnexen@gmail.com> | 2022-04-27 06:01:05 +0100 |
|---|---|---|
| committer | David Carlier <devnexen@gmail.com> | 2022-07-06 19:52:56 +0100 |
| commit | 48ef00e36f58c1debaec8d5612297b8819f7a690 (patch) | |
| tree | eb5afa1f1e330c7b63228625d4374a68fc7e41d0 | |
| parent | 14d288fe125813b130a6571bbf2ae49c5f247174 (diff) | |
| download | rust-48ef00e36f58c1debaec8d5612297b8819f7a690.tar.gz rust-48ef00e36f58c1debaec8d5612297b8819f7a690.zip | |
doc additions
| -rw-r--r-- | library/std/src/os/unix/net/datagram.rs | 19 | ||||
| -rw-r--r-- | library/std/src/os/unix/net/stream.rs | 15 | ||||
| -rw-r--r-- | library/std/src/sys/unix/net.rs | 5 |
3 files changed, 38 insertions, 1 deletions
diff --git a/library/std/src/os/unix/net/datagram.rs b/library/std/src/os/unix/net/datagram.rs index 8008acfd1c9..7f5d760481b 100644 --- a/library/std/src/os/unix/net/datagram.rs +++ b/library/std/src/os/unix/net/datagram.rs @@ -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 diff --git a/library/std/src/os/unix/net/stream.rs b/library/std/src/os/unix/net/stream.rs index 7eb06be3e09..7ecb81340ac 100644 --- a/library/std/src/os/unix/net/stream.rs +++ b/library/std/src/os/unix/net/stream.rs @@ -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) diff --git a/library/std/src/sys/unix/net.rs b/library/std/src/sys/unix/net.rs index 60ee52528c5..30667edafba 100644 --- a/library/std/src/sys/unix/net.rs +++ b/library/std/src/sys/unix/net.rs @@ -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))) } |
