Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix very slow poll_writable() #156

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/reactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,9 @@ impl Source {
panic::catch_unwind(|| w.wake()).ok();
}
state[dir].waker = Some(cx.waker().clone());
state[dir].ticks = Some((Reactor::get().ticker(), state[dir].tick));
if state[dir].ticks.is_none() {
state[dir].ticks = Some((Reactor::get().ticker(), state[dir].tick));
}

// Update interest in this I/O handle.
if was_empty {
Expand Down
20 changes: 20 additions & 0 deletions tests/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::thread;
use std::time::Duration;

use async_io::{Async, Timer};
use futures_lite::future::poll_fn;
use futures_lite::{future, prelude::*};
#[cfg(unix)]
use tempfile::tempdir;
Expand Down Expand Up @@ -155,6 +156,25 @@ fn udp_send_recv() -> io::Result<()> {
})
}

#[test]
fn test_poll_writable_iterations() -> io::Result<()> {
future::block_on(async {
let socket = Async::<UdpSocket>::bind(([127, 0, 0, 1], 0))?;

let mut attempts = 0;

poll_fn(|cx| {
attempts += 1;
socket.poll_writable(cx)
})
.await?;

assert!(attempts < 5);

Ok(())
})
}

#[cfg(unix)]
#[test]
fn udp_connect() -> io::Result<()> {
Expand Down
Loading