use std::time::Duration;
use nlink::netlink::{Connection, Route};
#[tokio::main]
async fn main() -> nlink::netlink::Result<()> {
let conn = Connection::<Route>::new()?;
assert_eq!(conn.get_timeout(), None);
println!("Default timeout: none");
let conn = conn.timeout(Duration::from_secs(5));
println!("Timeout set to: {:?}", conn.get_timeout().unwrap());
let links = conn.get_links().await?;
println!("Found {} interfaces (within timeout)", links.len());
let fast_conn = Connection::<Route>::new()?.timeout(Duration::from_nanos(1));
match fast_conn.get_links().await {
Ok(links) => println!("Got {} links (fast system!)", links.len()),
Err(e) if e.is_timeout() => println!("Operation timed out (expected with 1ns timeout)"),
Err(e) => return Err(e),
}
let conn = conn.no_timeout();
assert_eq!(conn.get_timeout(), None);
println!("Timeout cleared.");
Ok(())
}