Skip to content

Commit

Permalink
poll: Do not clear readiness on short read/writes. (#5881)
Browse files Browse the repository at this point in the history
The new mio_unsupported_force_poll_poll behaviour works the same as
Windows (using level-triggered APIs to mimic edge-triggered ones) and it
depends on intercepting an EAGAIN result to start polling the fd again.
  • Loading branch information
jasta committed Jul 19, 2023
1 parent f24b982 commit d64c8e3
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tokio/src/io/poll_evented.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,10 @@ feature! {
match self.io.as_ref().unwrap().read(b) {
Ok(n) => {
// if we read a partially full buffer, this is sufficient on unix to show
// that the socket buffer has been drained
if n > 0 && (!cfg!(windows) && n < len) {
// that the socket buffer has been drained. Unfortunately this assumption
// fails for level-triggered selectors (like on Windows or poll even for
// UNIX): https://github.com/tokio-rs/tokio/issues/5866
if n > 0 && (!cfg!(windows) && !cfg!(mio_unsupported_force_poll_poll) && n < len) {
self.registration.clear_readiness(evt);
}

Expand Down Expand Up @@ -196,8 +198,10 @@ feature! {
match self.io.as_ref().unwrap().write(buf) {
Ok(n) => {
// if we write only part of our buffer, this is sufficient on unix to show
// that the socket buffer is full
if n > 0 && (!cfg!(windows) && n < buf.len()) {
// that the socket buffer is full. Unfortunately this assumption
// fails for level-triggered selectors (like on Windows or poll even for
// UNIX): https://github.com/tokio-rs/tokio/issues/5866
if n > 0 && (!cfg!(windows) && !cfg!(mio_unsupported_force_poll_poll) && n < buf.len()) {
self.registration.clear_readiness(evt);
}

Expand Down

0 comments on commit d64c8e3

Please sign in to comment.