nispor / mozim

DHCP Client Daemon
Apache License 2.0
11 stars 9 forks source link

Introduce async API #12

Closed cathay4t closed 1 year ago

cathay4t commented 1 year ago

Introduced this async API via DhcpV4ClientAsync. Example usage:

let mut cli = DhcpV4ClientAsync::init(config, None).unwrap();

while let Some(l) = cli.next().await {
    match l {
        Ok(lease) => {
            println!("Got lease {lease:?}");
        }
        Err(e) => {
            eprintln!("Got error {e:?}");
            break;
        }
    }
}

We use Stream instead Future because we need to renew the lease with DHCP server.

Proxy mode is also works via initiating DhcpV4ClientAsync with DhcpV4Config::new_proxy();

Example and integration test included.

Misc: