Skip to content

Commit d64c8e3

Browse files
authored
poll: Do not clear readiness on short read/writes. (#5881)
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.
1 parent f24b982 commit d64c8e3

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

tokio/src/io/poll_evented.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,10 @@ feature! {
165165
match self.io.as_ref().unwrap().read(b) {
166166
Ok(n) => {
167167
// if we read a partially full buffer, this is sufficient on unix to show
168-
// that the socket buffer has been drained
169-
if n > 0 && (!cfg!(windows) && n < len) {
168+
// that the socket buffer has been drained. Unfortunately this assumption
169+
// fails for level-triggered selectors (like on Windows or poll even for
170+
// UNIX): https://github.com/tokio-rs/tokio/issues/5866
171+
if n > 0 && (!cfg!(windows) && !cfg!(mio_unsupported_force_poll_poll) && n < len) {
170172
self.registration.clear_readiness(evt);
171173
}
172174

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

0 commit comments

Comments
 (0)