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

Function test_v6_sendmmsg

tests/net/v6.rs:201–288  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

199#[test]
200#[cfg(target_os = "linux")]
201fn test_v6_sendmmsg() {
202 crate::init();
203
204 use std::net::TcpStream;
205
206 use rustix::io::IoSlice;
207 use rustix::net::addr::SocketAddrArg as _;
208 use rustix::net::{sendmmsg, MMsgHdr};
209
210 fn server(ready: Arc<(Mutex<u16>, Condvar)>) {
211 let connection_socket = socket(AddressFamily::INET6, SocketType::STREAM, None).unwrap();
212
213 let name = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 0, 0, 0);
214 bind(&connection_socket, &name).unwrap();
215
216 let who = getsockname(&connection_socket).unwrap();
217 let who = SocketAddrV6::try_from(who).unwrap();
218
219 listen(&connection_socket, 1).unwrap();
220
221 {
222 let (lock, cvar) = &*ready;
223 let mut port = lock.lock().unwrap();
224 *port = who.port();
225 cvar.notify_all();
226 }
227
228 let mut buffer = vec![0; 13];
229 let mut data_socket: TcpStream = accept(&connection_socket).unwrap().into();
230
231 std::io::Read::read_exact(&mut data_socket, &mut buffer).unwrap();
232 assert_eq!(String::from_utf8_lossy(&buffer), "hello...world");
233 }
234
235 fn client(ready: Arc<(Mutex<u16>, Condvar)>) {
236 let port = {
237 let (lock, cvar) = &*ready;
238 let mut port = lock.lock().unwrap();
239 while *port == 0 {
240 port = cvar.wait(port).unwrap();
241 }
242 *port
243 };
244
245 let addr = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), port, 0, 0);
246 let data_socket = socket(AddressFamily::INET6, SocketType::STREAM, None).unwrap();
247 connect(&data_socket, &addr).unwrap();
248
249 let mut off = 0;
250 while off < 2 {
251 let sent = sendmmsg(
252 &data_socket,
253 &mut [
254 MMsgHdr::new(&[IoSlice::new(b"hello")], &mut Default::default()),
255 MMsgHdr::new_with_addr(
256 &addr.as_any(),
257 &[IoSlice::new(b"...world")],
258 &mut Default::default(),

Callers

nothing calls this directly

Calls 3

initFunction · 0.70
serverFunction · 0.70
clientFunction · 0.70

Tested by

no test coverage detected