From 7e2fe10021459005e43840c34fb43bd7277453cd Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Sun, 30 Jun 2024 13:40:16 +0200 Subject: [PATCH 1/2] io: hardcode platform list in short-read optimization --- tokio/src/io/poll_evented.rs | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/tokio/src/io/poll_evented.rs b/tokio/src/io/poll_evented.rs index 3952a31e783..fb829748138 100644 --- a/tokio/src/io/poll_evented.rs +++ b/tokio/src/io/poll_evented.rs @@ -183,11 +183,35 @@ 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. 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) { + // When mio is using the epoll or kqueue selector, reading a partially full + // buffer is sufficient to show that the socket buffer has been drained. + // + // This optimization does not work for level-triggered selectors such as + // windows or when poll is used. + // + // Read more: + // https://github.com/tokio-rs/tokio/issues/5866 + #[cfg(all( + not(mio_unsupported_force_poll_poll), + any( + // epoll + target_os = "android", + target_os = "illumos", + target_os = "linux", + target_os = "redox", + // kqueue + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "tvos", + target_os = "visionos", + target_os = "watchos", + ) + ))] + if 0 < n && n < len { self.registration.clear_readiness(evt); } From d03ba27cd78d83333e9bb948f5cc8a97cf95cffa Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Tue, 2 Jul 2024 22:16:55 +0200 Subject: [PATCH 2/2] Fix unused vars warning --- tokio/src/io/poll_evented.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tokio/src/io/poll_evented.rs b/tokio/src/io/poll_evented.rs index fb829748138..73cb8e5809e 100644 --- a/tokio/src/io/poll_evented.rs +++ b/tokio/src/io/poll_evented.rs @@ -179,6 +179,9 @@ feature! { let evt = ready!(self.registration.poll_read_ready(cx))?; let b = &mut *(buf.unfilled_mut() as *mut [std::mem::MaybeUninit] as *mut [u8]); + + // used only when the cfgs below apply + #[allow(unused_variables)] let len = b.len(); match self.io.as_ref().unwrap().read(b) {