Skip to content

Commit 10f5a19

Browse files
committed
changes from feedback
1 parent 48ef00e commit 10f5a19

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

library/std/src/os/unix/net/datagram.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -839,20 +839,19 @@ impl UnixDatagram {
839839
}
840840

841841
/// Set the id of the socket for network filtering purpose
842-
/// and is only a setter.
843842
///
844843
/// ```no_run
845844
/// #![feature(unix_set_mark)]
846845
/// use std::os::unix::net::UnixDatagram;
847846
///
848847
/// fn main() -> std::io::Result<()> {
849848
/// let sock = UnixDatagram::unbound()?;
850-
/// sock.set_mark(32 as u32).expect("set_mark function failed");
849+
/// sock.set_mark(32)?;
851850
/// Ok(())
852851
/// }
853852
/// ```
854853
#[cfg(any(doc, target_os = "linux", target_os = "freebsd", target_os = "openbsd",))]
855-
#[unstable(feature = "unix_set_mark", issue = "none")]
854+
#[unstable(feature = "unix_set_mark", issue = "96467")]
856855
pub fn set_mark(&self, mark: u32) -> io::Result<()> {
857856
self.0.set_mark(mark)
858857
}

library/std/src/os/unix/net/stream.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,20 +425,19 @@ impl UnixStream {
425425
}
426426

427427
/// Set the id of the socket for network filtering purpose
428-
/// and is only a setter.
429428
///
430429
/// ```no_run
431430
/// #![feature(unix_set_mark)]
432431
/// use std::os::unix::net::UnixStream;
433432
///
434433
/// fn main() -> std::io::Result<()> {
435434
/// let sock = UnixStream::connect("/tmp/sock")?;
436-
/// sock.set_mark(32 as u32).expect("set_mark function failed");
435+
/// sock.set_mark(32)?;
437436
/// Ok(())
438437
/// }
439438
/// ```
440439
#[cfg(any(doc, target_os = "linux", target_os = "freebsd", target_os = "openbsd",))]
441-
#[unstable(feature = "unix_set_mark", issue = "none")]
440+
#[unstable(feature = "unix_set_mark", issue = "96467")]
442441
pub fn set_mark(&self, mark: u32) -> io::Result<()> {
443442
self.0.set_mark(mark)
444443
}

library/std/src/sys/unix/net.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -427,19 +427,15 @@ impl Socket {
427427
self.0.set_nonblocking(nonblocking)
428428
}
429429

430-
#[cfg(target_os = "linux")]
430+
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))]
431431
pub fn set_mark(&self, mark: u32) -> io::Result<()> {
432-
setsockopt(self, libc::SOL_SOCKET, libc::SO_MARK, mark as libc::c_int)
433-
}
434-
435-
#[cfg(target_os = "freebsd")]
436-
pub fn set_mark(&self, mark: u32) -> io::Result<()> {
437-
setsockopt(self, libc::SOL_SOCKET, libc::SO_USER_COOKIE, mark)
438-
}
439-
440-
#[cfg(target_os = "openbsd")]
441-
pub fn set_mark(&self, mark: u32) -> io::Result<()> {
442-
setsockopt(self, libc::SOL_SOCKET, libc::SO_RTABLE, mark as libc::c_int)
432+
#[cfg(target_os = "linux")]
433+
let option = libc::SO_MARK;
434+
#[cfg(target_os = "freebsd")]
435+
let option = libc::SO_USER_COOKIE;
436+
#[cfg(target_os = "openbsd")]
437+
let option = libc::SO_RTABLE;
438+
setsockopt(self, libc::SOL_SOCKET, option, mark as libc::c_int)
443439
}
444440

445441
pub fn take_error(&self) -> io::Result<Option<io::Error>> {

0 commit comments

Comments
 (0)