Explorar el Código

Fix an embarassing relative/absolute time mismatch in examples.

whitequark hace 7 años
padre
commit
b7b4877a85
Se han modificado 3 ficheros con 3 adiciones y 8 borrados
  1. 1 1
      examples/client.rs
  2. 1 6
      examples/ping.rs
  3. 1 1
      examples/server.rs

+ 1 - 1
examples/client.rs

@@ -90,6 +90,6 @@ fn main() {
 
         let timestamp = utils::millis_since(startup_time);
         let poll_at = iface.poll(&mut sockets, timestamp).expect("poll error");
-        phy_wait(fd, poll_at).expect("wait error");
+        phy_wait(fd, poll_at.map(|at| at.saturating_sub(timestamp))).expect("wait error");
     }
 }

+ 1 - 6
examples/ping.rs

@@ -147,12 +147,7 @@ fn main() {
         let timestamp = utils::millis_since(startup_time);
 
         let poll_at = iface.poll(&mut sockets, timestamp).expect("poll error");
-        let mut resume_at = Some(send_at);
-        if let Some(poll_at) = poll_at {
-            resume_at = resume_at.map(|at| cmp::min(at, poll_at))
-        }
-
-        debug!("waiting until {:?} ms", resume_at);
+        let resume_at = [poll_at, Some(send_at)].iter().flat_map(|x| *x).min();
         phy_wait(fd, resume_at.map(|at| at.saturating_sub(timestamp))).expect("wait error");
     }
 

+ 1 - 1
examples/server.rs

@@ -182,6 +182,6 @@ fn main() {
 
         let timestamp = utils::millis_since(startup_time);
         let poll_at = iface.poll(&mut sockets, timestamp).expect("poll error");
-        phy_wait(fd, poll_at).expect("wait error");
+        phy_wait(fd, poll_at.map(|at| at.saturating_sub(timestamp))).expect("wait error");
     }
 }