#![cfg(feature = "sys")]
use netmap_rs::prelude::*;
use std::time::Duration;
fn main() -> Result<(), Error> {
let nm = NetmapBuilder::new("netmap:eth0")
.nm_tx_rings(1)
.num_rx_rings(1)
.build()?;
let mut tx_ring = nm.tx_ring(0)?;
let mut rx_ring = nm.rx_ring(0)?;
tx_ring.send(b"hello world")?;
tx_ring.sync();
let mut received = false;
for _ in 0..10 {
while let Some(frame) = rx_ring.recv() {
println!("Received packet: {:?}", frame.payload());
assert_eq!(frame.payload(), b"hello world");
received = true;
break;
}
if received {
break;
}
std::thread::sleep(Duration::from_millis(100)); rx_ring.sync(); }
if !received {
return Err(Error::WouldBlock); }
Ok(())
}