#simulator #networking

nightly oni_simulator

Networking simulator

2 releases

✓ Uses Rust 2018 edition

0.1.2 Oct 13, 2018
0.1.0 Aug 14, 2018

#30 in Simulation

Download history 3/week @ 2018-10-02 24/week @ 2018-10-16 6/week @ 2018-10-23 2/week @ 2018-10-30 11/week @ 2018-11-06 6/week @ 2018-11-13 4/week @ 2018-11-20 4/week @ 2018-11-27 16/week @ 2018-12-04 3/week @ 2018-12-11 5/week @ 2018-12-18 15/week @ 2018-12-25

33 downloads per month
Used in 1 crate

MIT/Apache

40KB
1K SLoC

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)

lib.rs:

Example

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);

Dependencies

~3.5MB
~67K SLoC