From ab2a8db4d3962def51235c813a09880fcfcf9712 Mon Sep 17 00:00:00 2001 From: Astro Date: Fri, 3 Apr 2020 00:18:04 +0200 Subject: [PATCH] libasync: pass time --- experiments/src/main.rs | 7 +++++-- libasync/src/smoltcp/mod.rs | 17 ++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/experiments/src/main.rs b/experiments/src/main.rs index 3f46787..9aec44e 100644 --- a/experiments/src/main.rs +++ b/experiments/src/main.rs @@ -241,8 +241,11 @@ pub fn main_core0() { .map_err(|e| println!("Connection: {:?}", e)); }); - Sockets::run(&mut iface); - // let mut time = 0u32; + let mut time = 0u32; + Sockets::run(&mut iface, || { + time += 1; + Instant::from_millis(time) + }); // loop { // time += 1; // let timestamp = Instant::from_millis(time); diff --git a/libasync/src/smoltcp/mod.rs b/libasync/src/smoltcp/mod.rs index 750f13f..b54fb30 100644 --- a/libasync/src/smoltcp/mod.rs +++ b/libasync/src/smoltcp/mod.rs @@ -35,15 +35,20 @@ impl Sockets { sockets, wakers, }; + // println!("sockets initialized"); unsafe { SOCKETS = Some(instance); } } /// Block and run executor indefinitely while polling the smoltcp /// iface - pub fn run<'b, 'c, 'e, D: for<'d> Device<'d>>(iface: &mut EthernetInterface<'b, 'c, 'e, D>) { + pub fn run<'b, 'c, 'e, D: for<'d> Device<'d>>( + iface: &mut EthernetInterface<'b, 'c, 'e, D>, + mut get_time: impl FnMut() -> Instant, + ) { task::block_on(async { loop { - Self::instance().poll(iface); + let instant = get_time(); + Self::instance().poll(iface, instant); task::r#yield().await; } }); @@ -53,9 +58,11 @@ impl Sockets { unsafe { SOCKETS.as_ref().expect("Sockets") } } - fn poll<'b, 'c, 'e, D: for<'d> Device<'d>>(&self, iface: &mut EthernetInterface<'b, 'c, 'e, D>) { - // TODO: - let instant = Instant::from_millis(0); + fn poll<'b, 'c, 'e, D: for<'d> Device<'d>>( + &self, + iface: &mut EthernetInterface<'b, 'c, 'e, D>, + instant: Instant + ) { let processed = { let mut sockets = self.sockets.borrow_mut(); match iface.poll(&mut sockets, instant) {