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

Function test_v4_sendmmsg

tests/net/v4.rs:202–289  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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