1 use crate::os::unix::net::UnixStream;
2 use libc::{getegid, geteuid, getpid};
8 target_os = "dragonfly",
14 fn test_socket_pair() {
15 // Create two connected sockets and get their peer credentials. They should be equal.
16 let (sock_a, sock_b) = UnixStream::pair().unwrap();
17 let (cred_a, cred_b) = (sock_a.peer_cred().unwrap(), sock_b.peer_cred().unwrap());
18 assert_eq!(cred_a, cred_b);
20 // Check that the UID and GIDs match up.
21 let uid = unsafe { geteuid() };
22 let gid = unsafe { getegid() };
23 assert_eq!(cred_a.uid, uid);
24 assert_eq!(cred_a.gid, gid);
28 #[cfg(any(target_os = "linux", target_os = "ios", target_os = "macos",))]
29 fn test_socket_pair_pids(arg: Type) -> RetType {
30 // Create two connected sockets and get their peer credentials.
31 let (sock_a, sock_b) = UnixStream::pair().unwrap();
32 let (cred_a, cred_b) = (sock_a.peer_cred().unwrap(), sock_b.peer_cred().unwrap());
34 // On supported platforms (see the cfg above), the credentials should always include the PID.
35 let pid = unsafe { getpid() };
36 assert_eq!(cred_a.pid, Some(pid));
37 assert_eq!(cred_b.pid, Some(pid));