oni_simulator 0.1.0

Networking simulator
docs.rs failed to build oni_simulator-0.1.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: oni_simulator-0.1.2

Latest version Documentation License

use oni_simulator::{Simulator, DefaultMTU};
use std::io;

let sim = Simulator::<DefaultMTU>::new();

let from = "[::1]:1111".parse().unwrap();
let to   = "[::1]:2222".parse().unwrap();

let from = sim.add_socket(from);
let to   = sim.add_socket(to);

from.send_to(&[1, 2, 3], to.local_addr()).unwrap();
sim.advance();

let mut buf = [0u8; 4];
let (bytes, addr) = to.recv_from(&mut buf[..]).unwrap();
assert_eq!(bytes, 3);
assert_eq!(addr, from.local_addr());
assert_eq!(&buf[..bytes], &[1, 2, 3]);

let err = to.recv_from(&mut buf[..]).unwrap_err();
assert_eq!(err.kind(), io::ErrorKind::WouldBlock)