MCPcopy Create free account
hub / github.com/bytecodealliance/rustix / client

Function client

tests/net/unix.rs:64–95  ·  view source on GitHub ↗
(ready: Arc<(Mutex<bool>, Condvar)>, path: &Path, runs: &[(&[&str], i32)])

Source from the content-addressed store, hash-verified

62}
63
64fn client(ready: Arc<(Mutex<bool>, Condvar)>, path: &Path, runs: &[(&[&str], i32)]) {
65 {
66 let (lock, cvar) = &*ready;
67 let mut started = lock.lock().unwrap();
68 while !*started {
69 started = cvar.wait(started).unwrap();
70 }
71 }
72
73 let addr = SocketAddrUnix::new(path).unwrap();
74 let mut buffer = [0; BUFFER_SIZE];
75
76 for (args, sum) in runs {
77 let data_socket = socket(AddressFamily::UNIX, SocketType::SEQPACKET, None).unwrap();
78 connect(&data_socket, &addr).unwrap();
79
80 for arg in *args {
81 write(&data_socket, arg.as_bytes()).unwrap();
82 }
83 write(&data_socket, b"sum").unwrap();
84
85 let nread = read(&data_socket, &mut buffer).unwrap();
86 assert_eq!(
87 i32::from_str(&String::from_utf8_lossy(&buffer[..nread])).unwrap(),
88 *sum
89 );
90 }
91
92 let data_socket = socket(AddressFamily::UNIX, SocketType::SEQPACKET, None).unwrap();
93 connect(&data_socket, &addr).unwrap();
94 write(&data_socket, b"exit").unwrap();
95}
96
97#[test]
98#[cfg(not(target_os = "freebsd"))] // TODO: Investigate why these tests fail on FreeBSD.

Callers 5

test_unixFunction · 0.70
do_test_unix_msgFunction · 0.70
test_unix_msg_with_comboFunction · 0.70

Calls 5

socketFunction · 0.50
connectFunction · 0.50
writeFunction · 0.50
readFunction · 0.50
as_bytesMethod · 0.45

Tested by 3

test_unixFunction · 0.56
test_unix_msg_with_comboFunction · 0.56