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

Function client

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

Source from the content-addressed store, hash-verified

59}
60
61fn client(ready: Arc<(Mutex<bool>, Condvar)>, path: &Path, runs: &[(&[&str], i32)]) {
62 {
63 let (lock, cvar) = &*ready;
64 let mut started = lock.lock().unwrap();
65 while !*started {
66 started = cvar.wait(started).unwrap();
67 }
68 }
69
70 let addr = SocketAddrUnix::new(path).unwrap();
71 let mut buffer = vec![0; BUFFER_SIZE];
72
73 for (args, sum) in runs {
74 let data_socket = socket(AddressFamily::UNIX, SocketType::SEQPACKET, None).unwrap();
75 connect(&data_socket, &addr).unwrap();
76
77 for arg in *args {
78 write(&data_socket, arg.as_bytes()).unwrap();
79 }
80 write(&data_socket, b"sum").unwrap();
81
82 let nread = read(&data_socket, &mut buffer).unwrap();
83 assert_eq!(
84 i32::from_str(&String::from_utf8_lossy(&buffer[..nread])).unwrap(),
85 *sum
86 );
87 }
88
89 let data_socket = socket(AddressFamily::UNIX, SocketType::SEQPACKET, None).unwrap();
90 connect(&data_socket, &addr).unwrap();
91 write(&data_socket, b"exit").unwrap();
92}
93
94#[test]
95#[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