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

Function do_test_unix_msg

tests/net/unix_alloc.rs:133–257  ·  view source on GitHub ↗

TODO: Investigate why these tests fail on FreeBSD.

(addr: SocketAddrUnix)

Source from the content-addressed store, hash-verified

131#[cfg(not(any(target_os = "espidf", target_os = "redox", target_os = "wasi")))]
132#[cfg(not(target_os = "freebsd"))] // TODO: Investigate why these tests fail on FreeBSD.
133fn do_test_unix_msg(addr: SocketAddrUnix) {
134 use rustix::io::{IoSlice, IoSliceMut};
135 use rustix::net::{recvmsg, sendmsg, RecvFlags, ReturnFlags, SendFlags};
136
137 let server = {
138 let connection_socket = socket(AddressFamily::UNIX, SocketType::SEQPACKET, None).unwrap();
139 bind(&connection_socket, &addr).unwrap();
140 listen(&connection_socket, 1).unwrap();
141
142 move || {
143 let mut buffer = vec![0; BUFFER_SIZE];
144 'exit: loop {
145 let data_socket = accept(&connection_socket).unwrap();
146 let mut sum = 0;
147 loop {
148 let result = recvmsg(
149 &data_socket,
150 &mut [IoSliceMut::new(&mut buffer)],
151 &mut Default::default(),
152 RecvFlags::empty(),
153 )
154 .unwrap();
155 let nread = result.bytes;
156
157 assert_eq!(result.flags, ReturnFlags::empty());
158
159 if &buffer[..nread] == b"exit" {
160 break 'exit;
161 }
162 if &buffer[..nread] == b"sum" {
163 break;
164 }
165
166 sum += i32::from_str(&String::from_utf8_lossy(&buffer[..nread])).unwrap();
167 }
168
169 let data = sum.to_string();
170 sendmsg(
171 &data_socket,
172 &[IoSlice::new(data.as_bytes())],
173 &mut Default::default(),
174 SendFlags::empty(),
175 )
176 .unwrap();
177 }
178 }
179 };
180
181 let client = move || {
182 let mut buffer = vec![0; BUFFER_SIZE];
183 let runs: &[(&[&str], i32)] = &[
184 (&["1", "2"], 3),
185 (&["4", "77", "103"], 184),
186 (&["5", "78", "104"], 187),
187 (&[], 0),
188 ];
189
190 for (args, sum) in runs {

Callers 2

test_unix_msgFunction · 0.70
test_abstract_unix_msgFunction · 0.70

Calls 10

serverFunction · 0.70
clientFunction · 0.70
socketFunction · 0.50
bindFunction · 0.50
listenFunction · 0.50
acceptFunction · 0.50
recvmsgFunction · 0.50
sendmsgFunction · 0.50
connectFunction · 0.50
as_bytesMethod · 0.45

Tested by 2

test_unix_msgFunction · 0.56
test_abstract_unix_msgFunction · 0.56