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

Function server

tests/net/unix.rs:27–62  ·  view source on GitHub ↗
(ready: Arc<(Mutex<bool>, Condvar)>, path: &Path)

Source from the content-addressed store, hash-verified

25const BUFFER_SIZE: usize = 20;
26
27fn server(ready: Arc<(Mutex<bool>, Condvar)>, path: &Path) {
28 let connection_socket = socket(AddressFamily::UNIX, SocketType::SEQPACKET, None).unwrap();
29
30 let name = SocketAddrUnix::new(path).unwrap();
31 bind(&connection_socket, &name).unwrap();
32 listen(&connection_socket, 1).unwrap();
33
34 {
35 let (lock, cvar) = &*ready;
36 let mut started = lock.lock().unwrap();
37 *started = true;
38 cvar.notify_all();
39 }
40
41 let mut buffer = [0; BUFFER_SIZE];
42 'exit: loop {
43 let data_socket = accept(&connection_socket).unwrap();
44 let mut sum = 0;
45 loop {
46 let nread = read(&data_socket, &mut buffer).unwrap();
47
48 if &buffer[..nread] == b"exit" {
49 break 'exit;
50 }
51 if &buffer[..nread] == b"sum" {
52 break;
53 }
54
55 sum += i32::from_str(&String::from_utf8_lossy(&buffer[..nread])).unwrap();
56 }
57
58 write(&data_socket, DecInt::new(sum).as_bytes()).unwrap();
59 }
60
61 unlinkat(CWD, path, AtFlags::empty()).unwrap();
62}
63
64fn client(ready: Arc<(Mutex<bool>, Condvar)>, path: &Path, runs: &[(&[&str], i32)]) {
65 {

Callers 5

test_unixFunction · 0.70
do_test_unix_msgFunction · 0.70
test_unix_msg_with_comboFunction · 0.70

Calls 8

socketFunction · 0.50
bindFunction · 0.50
listenFunction · 0.50
acceptFunction · 0.50
readFunction · 0.50
writeFunction · 0.50
unlinkatFunction · 0.50
as_bytesMethod · 0.45

Tested by 3

test_unixFunction · 0.56
test_unix_msg_with_comboFunction · 0.56