Skip to content

Commit

Permalink
Conditionally compile peer credentials feature for supported platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Ellis committed Sep 14, 2020
1 parent fa697df commit 72eef61
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions library/std/src/sys/unix/ext/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,15 @@ impl UnixStream {
/// }
/// ```
#[unstable(feature = "peer_credentials_unix_socket", issue = "42839", reason = "unstable")]
#[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos",
target_os = "openbsd"
))]
pub fn peer_cred(&self) -> io::Result<UCred> {
ucred::peer_cred(self)
}
Expand Down
9 changes: 9 additions & 0 deletions library/std/src/sys/unix/ext/ucred/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ use crate::os::unix::net::UnixStream;
use libc::{getegid, geteuid};

#[test]
#[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos",
target_os = "openbsd"
))]
fn test_socket_pair() {
// Create two connected sockets and get their peer credentials. They should be equal.
let (sock_a, sock_b) = UnixStream::pair().unwrap();
Expand Down

0 comments on commit 72eef61

Please sign in to comment.