From 3b7dfbc72f9f3706ac4800a25b3df055b995ee61 Mon Sep 17 00:00:00 2001 From: Nikolay Arhipov Date: Wed, 17 Apr 2024 10:13:33 +0300 Subject: [PATCH 01/10] feat: ported to Vita target --- Cargo.toml | 7 ++++++- src/poll.rs | 25 +++++++++++++++++++++++-- tests/concurrent_modification.rs | 2 +- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5730302..9f49000 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,10 @@ name = "polling" # - Update CHANGELOG.md # - Create "v3.x.y" git tag version = "3.6.0" -authors = ["Stjepan Glavina ", "John Nunley "] +authors = [ + "Stjepan Glavina ", + "John Nunley ", +] edition = "2021" rust-version = "1.63" description = "Portable interface to epoll, kqueue, event ports, and IOCP" @@ -55,4 +58,6 @@ socket2 = "0.5.5" [target.'cfg(unix)'.dev-dependencies] libc = "0.2" + +[target.'cfg(all(unix, not(target_os="vita")))'.dev-dependencies] signal-hook = "0.3.17" diff --git a/src/poll.rs b/src/poll.rs index 13c742e..8183188 100644 --- a/src/poll.rs +++ b/src/poll.rs @@ -222,7 +222,28 @@ impl Poller { if self.notified.swap(false, Ordering::SeqCst) { // `notify` will have sent a notification in case we were polling. We weren't, // so remove it. - return self.notify.pop_notification(); + + // Pipes on Vita do not guarantee that after `write` call succeeds, the + // data becomes immediately available for reading on the other side of the pipe. + // To ensure that the notification is not lost, the read side of the pipe is temporarily + // switched to blocking for a single `read` call. + #[cfg(target_os = "vita")] + rustix::fs::fcntl_setfl( + &self.notify.read_pipe, + rustix::fs::fcntl_getfl(&self.notify.read_pipe)? + & !rustix::fs::OFlags::NONBLOCK, + )?; + + let notification = self.notify.pop_notification(); + + #[cfg(target_os = "vita")] + rustix::fs::fcntl_setfl( + &self.notify.read_pipe, + rustix::fs::fcntl_getfl(&self.notify.read_pipe)? + | rustix::fs::OFlags::NONBLOCK, + )?; + + return notification; } else if self.waiting_operations.load(Ordering::SeqCst) == 0 { break; } @@ -646,7 +667,7 @@ mod notify { pub(super) struct Notify { /// The file descriptor of the read half of the notify pipe. This is also stored as the first /// file descriptor in `fds.poll_fds`. - read_pipe: OwnedFd, + pub(super) read_pipe: OwnedFd, /// The file descriptor of the write half of the notify pipe. /// /// Data is written to this to wake up the current instance of `Poller::wait`, which can occur when the diff --git a/tests/concurrent_modification.rs b/tests/concurrent_modification.rs index ab3e5fb..160ee33 100644 --- a/tests/concurrent_modification.rs +++ b/tests/concurrent_modification.rs @@ -76,7 +76,7 @@ fn concurrent_modify() -> io::Result<()> { Ok(()) } -#[cfg(unix)] +#[cfg(unix, not(target_os = "vita"))] #[test] fn concurrent_interruption() -> io::Result<()> { struct MakeItSend(T); From b8679f46694dba576313f625e3519cd62c2c38b2 Mon Sep 17 00:00:00 2001 From: Nikolay Arhipov Date: Wed, 17 Apr 2024 10:14:25 +0300 Subject: [PATCH 02/10] Reverted formatting --- Cargo.toml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9f49000..6206c6c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,10 +4,7 @@ name = "polling" # - Update CHANGELOG.md # - Create "v3.x.y" git tag version = "3.6.0" -authors = [ - "Stjepan Glavina ", - "John Nunley ", -] +authors = ["Stjepan Glavina ", "John Nunley "] edition = "2021" rust-version = "1.63" description = "Portable interface to epoll, kqueue, event ports, and IOCP" From ac07039ddb3e7fb8a81139bd14904cb41cecf1f0 Mon Sep 17 00:00:00 2001 From: Nikolay Arhipov Date: Wed, 17 Apr 2024 10:26:54 +0300 Subject: [PATCH 03/10] Typo --- tests/concurrent_modification.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/concurrent_modification.rs b/tests/concurrent_modification.rs index 160ee33..f4598c0 100644 --- a/tests/concurrent_modification.rs +++ b/tests/concurrent_modification.rs @@ -76,7 +76,7 @@ fn concurrent_modify() -> io::Result<()> { Ok(()) } -#[cfg(unix, not(target_os = "vita"))] +#[cfg(all(unix, not(target_os = "vita")))] #[test] fn concurrent_interruption() -> io::Result<()> { struct MakeItSend(T); From d1490e549bbf6fefd57e98dda701556f67e00db6 Mon Sep 17 00:00:00 2001 From: Nikolay Arhipov Date: Fri, 19 Apr 2024 09:44:43 +0300 Subject: [PATCH 04/10] Added CI check and inlined hack into pop_notification --- .github/workflows/ci.yml | 3 +++ src/poll.rs | 41 ++++++++++++++++++---------------------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ef7d339..e27998b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -126,6 +126,9 @@ jobs: - name: Check haiku if: startsWith(matrix.rust, 'nightly') && matrix.os == 'ubuntu-latest' run: cargo check -Z build-std --target x86_64-unknown-haiku + - name: Check vita + if: startsWith(matrix.rust, 'nightly') && matrix.os == 'ubuntu-latest' + run: cargo check -Z build-std --target armv7-sony-vita-newlibeabihf wine: runs-on: ubuntu-22.04 diff --git a/src/poll.rs b/src/poll.rs index 8183188..cba72fa 100644 --- a/src/poll.rs +++ b/src/poll.rs @@ -222,28 +222,7 @@ impl Poller { if self.notified.swap(false, Ordering::SeqCst) { // `notify` will have sent a notification in case we were polling. We weren't, // so remove it. - - // Pipes on Vita do not guarantee that after `write` call succeeds, the - // data becomes immediately available for reading on the other side of the pipe. - // To ensure that the notification is not lost, the read side of the pipe is temporarily - // switched to blocking for a single `read` call. - #[cfg(target_os = "vita")] - rustix::fs::fcntl_setfl( - &self.notify.read_pipe, - rustix::fs::fcntl_getfl(&self.notify.read_pipe)? - & !rustix::fs::OFlags::NONBLOCK, - )?; - - let notification = self.notify.pop_notification(); - - #[cfg(target_os = "vita")] - rustix::fs::fcntl_setfl( - &self.notify.read_pipe, - rustix::fs::fcntl_getfl(&self.notify.read_pipe)? - | rustix::fs::OFlags::NONBLOCK, - )?; - - return notification; + return self.notify.pop_notification(); } else if self.waiting_operations.load(Ordering::SeqCst) == 0 { break; } @@ -667,7 +646,7 @@ mod notify { pub(super) struct Notify { /// The file descriptor of the read half of the notify pipe. This is also stored as the first /// file descriptor in `fds.poll_fds`. - pub(super) read_pipe: OwnedFd, + read_pipe: OwnedFd, /// The file descriptor of the write half of the notify pipe. /// /// Data is written to this to wake up the current instance of `Poller::wait`, which can occur when the @@ -720,8 +699,24 @@ mod notify { /// Pops a notification (if any) from the pipe. pub(super) fn pop_notification(&self) -> Result<(), io::Error> { + // Pipes on Vita do not guarantee that after `write` call succeeds, the + // data becomes immediately available for reading on the other side of the pipe. + // To ensure that the notification is not lost, the read side of the pipe is temporarily + // switched to blocking for a single `read` call. + #[cfg(target_os = "vita")] + rustix::fs::fcntl_setfl( + &self.read_pipe, + rustix::fs::fcntl_getfl(&self.read_pipe)? & !rustix::fs::OFlags::NONBLOCK, + )?; + read(&self.read_pipe, &mut [0; 1])?; + #[cfg(target_os = "vita")] + rustix::fs::fcntl_setfl( + &self.read_pipe, + rustix::fs::fcntl_getfl(&self.read_pipe)? | rustix::fs::OFlags::NONBLOCK, + )?; + Ok(()) } From a28512f4b759480ce5179817ee24c4db2660e5e5 Mon Sep 17 00:00:00 2001 From: Nikolay Arhipov Date: Fri, 19 Apr 2024 09:49:03 +0300 Subject: [PATCH 05/10] Actually run checks for nightly targets on nightly --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e27998b..83b4dbb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -81,6 +81,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest] + rust: [nightly, stable] steps: - uses: actions/checkout@v4 - name: Install Rust From 718fd34e34316d3dbdf42bb057c99e2e2b13a762 Mon Sep 17 00:00:00 2001 From: Nikolay Arhipov Date: Fri, 19 Apr 2024 09:53:14 +0300 Subject: [PATCH 06/10] Fixup --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 83b4dbb..8a197fc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -85,7 +85,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Install Rust - run: rustup update stable + run: rustup update ${{ matrix.rust }} - name: Install cross uses: taiki-e/install-action@cross - name: Add rust-src From 11e5f9c92af2fdf202339b0e147117aa5ecb07d9 Mon Sep 17 00:00:00 2001 From: Nikolay Arhipov Date: Fri, 19 Apr 2024 10:01:12 +0300 Subject: [PATCH 07/10] Explicit +nightly --- .github/workflows/ci.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8a197fc..db252ad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -122,14 +122,13 @@ jobs: cargo check --target x86_64-unknown-redox - name: HermitOS if: startsWith(matrix.rust, 'nightly') && matrix.os == 'ubuntu-latest' - run: | - cargo -Zbuild-std check --target x86_64-unknown-hermit + run: cargo +nightly check -Z build-std --target x86_64-unknown-hermit - name: Check haiku if: startsWith(matrix.rust, 'nightly') && matrix.os == 'ubuntu-latest' - run: cargo check -Z build-std --target x86_64-unknown-haiku + run: cargo +nightly check -Z build-std --target x86_64-unknown-haiku - name: Check vita if: startsWith(matrix.rust, 'nightly') && matrix.os == 'ubuntu-latest' - run: cargo check -Z build-std --target armv7-sony-vita-newlibeabihf + run: cargo +nightly check -Z build-std --target armv7-sony-vita-newlibeabihf wine: runs-on: ubuntu-22.04 From cba007cec78f2ab1a8d12fec1b7b1591c34b04c5 Mon Sep 17 00:00:00 2001 From: Nikolay Arhipov Date: Fri, 19 Apr 2024 11:10:55 +0300 Subject: [PATCH 08/10] Add src to nightly? --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index db252ad..e020664 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -90,7 +90,7 @@ jobs: uses: taiki-e/install-action@cross - name: Add rust-src if: startsWith(matrix.rust, 'nightly') - run: rustup component add rust-src + run: rustup +nightly component add rust-src # We don't test BSDs, since we already test them in Cirrus. - name: Android if: startsWith(matrix.os, 'ubuntu') From 443cd750e41a0b0284bb1a19ae6871b7906fb3db Mon Sep 17 00:00:00 2001 From: Nikolay Arhipov Date: Sat, 20 Apr 2024 09:06:27 +0300 Subject: [PATCH 09/10] Cache result of read --- src/poll.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/poll.rs b/src/poll.rs index cba72fa..dfbca14 100644 --- a/src/poll.rs +++ b/src/poll.rs @@ -709,7 +709,7 @@ mod notify { rustix::fs::fcntl_getfl(&self.read_pipe)? & !rustix::fs::OFlags::NONBLOCK, )?; - read(&self.read_pipe, &mut [0; 1])?; + let result = read(&self.read_pipe, &mut [0; 1]); #[cfg(target_os = "vita")] rustix::fs::fcntl_setfl( @@ -717,6 +717,8 @@ mod notify { rustix::fs::fcntl_getfl(&self.read_pipe)? | rustix::fs::OFlags::NONBLOCK, )?; + result?; + Ok(()) } From bf7196cae0f3118706b27e252ebefa30e06a0182 Mon Sep 17 00:00:00 2001 From: Nikolay Arhipov Date: Sat, 20 Apr 2024 09:16:47 +0300 Subject: [PATCH 10/10] Fixed a couple typos in the docs --- src/lib.rs | 2 +- src/os/iocp.rs | 2 +- src/poll.rs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1be752b..018f2e6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -402,7 +402,7 @@ impl Event { /// Tells if this event is the result of a connection failure. /// - /// This function checks if an error exist,particularlly useful in detecting if TCP connection failed. It corresponds to the `EPOLLERR` event in Linux + /// This function checks if an error exist, particularly useful in detecting if TCP connection failed. It corresponds to the `EPOLLERR` event in Linux /// and `CONNECT_FAILED` event in Windows IOCP. /// /// ## Caveats diff --git a/src/os/iocp.rs b/src/os/iocp.rs index bc37843..3370118 100644 --- a/src/os/iocp.rs +++ b/src/os/iocp.rs @@ -1,4 +1,4 @@ -//! Functionality that is only availale for IOCP-based platforms. +//! Functionality that is only available for IOCP-based platforms. pub use crate::sys::CompletionPacket; diff --git a/src/poll.rs b/src/poll.rs index dfbca14..45407c7 100644 --- a/src/poll.rs +++ b/src/poll.rs @@ -685,7 +685,7 @@ mod notify { self.read_pipe.as_fd() } - /// Provides the poll flags to be used when registering the read half of the botify pipe with the `Poller`. + /// Provides the poll flags to be used when registering the read half of the notify pipe with the `Poller`. pub(super) fn poll_flags(&self) -> PollFlags { PollFlags::RDNORM } @@ -747,7 +747,7 @@ mod notify { /// A notification pipe. /// - /// This implementation uses ther `eventfd` syscall to send notifications. + /// This implementation uses the `eventfd` syscall to send notifications. #[derive(Debug)] pub(super) struct Notify { /// The file descriptor of the eventfd object. This is also stored as the first