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

Function server

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

Source from the content-addressed store, hash-verified

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

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