Skip to content

Commit

Permalink
Poll receiver once to register waker
Browse files Browse the repository at this point in the history
  • Loading branch information
mxinden committed Feb 20, 2024
1 parent b439d3c commit ac6428f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions neqo-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ time = { version = "0.3", features = ["formatting"] }
tokio = { version = "1", features = ["net", "time", "macros", "rt", "rt-multi-thread"], optional = true }

[dev-dependencies]
# TODO: Needed?
futures = "0.3"
test-fixture = { path = "../test-fixture" }

[features]
Expand Down
13 changes: 10 additions & 3 deletions neqo-common/src/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,10 @@ impl Socket {

#[cfg(test)]
mod tests {
use std::time::Duration;
use std::{time::Duration, task::Poll, pin::Pin};

use tokio::time::sleep;
use futures::{future::FutureExt, Future};

use super::*;
use crate::{IpTos, IpTosDscp, IpTosEcn};
Expand All @@ -137,6 +138,12 @@ mod tests {
let receiver_addr: SocketAddr = "127.0.0.1:0".parse().unwrap();
let receiver = Socket::bind(receiver_addr)?;
println!("receiver bind");
futures::future::poll_fn(|cx| {
let mut p = std::pin::pin!(receiver.readable());
assert!(p.as_mut().poll(cx).is_pending());
Poll::Ready(())
}).await;
println!("receiver polled pending");

sleep(Duration::from_millis(100)).await;

Expand All @@ -156,8 +163,8 @@ mod tests {

sleep(Duration::from_millis(100)).await;

// receiver.readable().await?;
// println!("readable");
receiver.readable().await?;
println!("readable");
let received_datagram = receiver
.recv(&receiver_addr)
.expect("receive to succeed")
Expand Down

0 comments on commit ac6428f

Please sign in to comment.