Conditionally compile peer credentials feature for supported platforms

This commit is contained in:
Joe Ellis 2020-09-08 16:08:21 +01:00
parent fa697dfa81
commit 72eef6168f
2 changed files with 18 additions and 0 deletions

View File

@ -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)
}

View File

@ -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();