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

Function do_test_unix_msg

tests/net/unix.rs:136–261  ·  view source on GitHub ↗

TODO: Investigate why these tests fail on FreeBSD.

(addr: SocketAddrUnix)

Source from the content-addressed store, hash-verified

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