From 3ecd41f34f153abbfd0ee25a268d0d3746d3f967 Mon Sep 17 00:00:00 2001 From: John Nunley Date: Wed, 28 Jun 2023 19:57:59 -0700 Subject: [PATCH] Bump to rustix v0.38 --- .cirrus.yml | 15 --------------- Cargo.toml | 2 +- src/epoll.rs | 31 ++++++++++++++++++++----------- src/kqueue.rs | 10 +++++----- src/lib.rs | 3 +-- src/os/kqueue.rs | 4 ++-- src/poll.rs | 7 +++---- src/port.rs | 3 ++- 8 files changed, 34 insertions(+), 41 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index d1e8a7a..f34e6ab 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -28,11 +28,6 @@ freebsd_task: - sudo sysctl net.inet.tcp.blackhole=0 - . $HOME/.cargo/env - cargo test --target $TARGET - # Test async-io - - git clone https://github.com/smol-rs/async-io.git - - echo '[patch.crates-io]' >> async-io/Cargo.toml - - echo 'polling = { path = ".." }' >> async-io/Cargo.toml - - cargo test --target $TARGET --manifest-path=async-io/Cargo.toml netbsd_task: name: test ($TARGET) @@ -49,11 +44,6 @@ netbsd_task: test_script: - . $HOME/.cargo/env - cargo test - # Test async-io - - git clone https://github.com/smol-rs/async-io.git - - echo '[patch.crates-io]' >> async-io/Cargo.toml - - echo 'polling = { path = ".." }' >> async-io/Cargo.toml - - cargo test --manifest-path=async-io/Cargo.toml openbsd_task: name: test ($TARGET) @@ -69,8 +59,3 @@ openbsd_task: - pkg_add git rust test_script: - cargo test - # Test async-io - - git clone https://github.com/smol-rs/async-io.git - - echo '[patch.crates-io]' >> async-io/Cargo.toml - - echo 'polling = { path = ".." }' >> async-io/Cargo.toml - - cargo test --manifest-path=async-io/Cargo.toml diff --git a/Cargo.toml b/Cargo.toml index 137100c..479c130 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ tracing = { version = "0.1.37", default-features = false } [target.'cfg(any(unix, target_os = "fuchsia", target_os = "vxworks"))'.dependencies] libc = "0.2.77" -rustix = { version = "0.37.11", features = ["process", "time", "fs", "std"], default-features = false } +rustix = { version = "0.38", features = ["event", "fs", "pipe", "process", "std", "time"], default-features = false } [target.'cfg(windows)'.dependencies] bitflags = "2" diff --git a/src/epoll.rs b/src/epoll.rs index 39996ba..4d21bbe 100644 --- a/src/epoll.rs +++ b/src/epoll.rs @@ -5,8 +5,9 @@ use std::io; use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, RawFd}; use std::time::Duration; +use rustix::event::{epoll, eventfd, EventfdFlags}; use rustix::fd::OwnedFd; -use rustix::io::{epoll, eventfd, read, write, EventfdFlags}; +use rustix::io::{read, write}; use rustix::time::{ timerfd_create, timerfd_settime, Itimerspec, TimerfdClockId, TimerfdFlags, TimerfdTimerFlags, Timespec, @@ -31,7 +32,7 @@ impl Poller { // Create an epoll instance. // // Use `epoll_create1` with `EPOLL_CLOEXEC`. - let epoll_fd = epoll::epoll_create(epoll::CreateFlags::CLOEXEC)?; + let epoll_fd = epoll::create(epoll::CreateFlags::CLOEXEC)?; // Set up eventfd and timerfd. let event_fd = eventfd(0, EventfdFlags::CLOEXEC | EventfdFlags::NONBLOCK)?; @@ -101,10 +102,10 @@ impl Poller { ); let _enter = span.enter(); - epoll::epoll_add( + epoll::add( &self.epoll_fd, unsafe { rustix::fd::BorrowedFd::borrow_raw(fd) }, - ev.key as u64, + epoll::EventData::new_u64(ev.key as u64), epoll_flags(&ev, mode), )?; @@ -121,7 +122,12 @@ impl Poller { ); let _enter = span.enter(); - epoll::epoll_mod(&self.epoll_fd, fd, ev.key as u64, epoll_flags(&ev, mode))?; + epoll::modify( + &self.epoll_fd, + fd, + epoll::EventData::new_u64(ev.key as u64), + epoll_flags(&ev, mode), + )?; Ok(()) } @@ -135,7 +141,7 @@ impl Poller { ); let _enter = span.enter(); - epoll::epoll_del(&self.epoll_fd, fd)?; + epoll::delete(&self.epoll_fd, fd)?; Ok(()) } @@ -195,7 +201,7 @@ impl Poller { }; // Wait for I/O events. - epoll::epoll_wait(&self.epoll_fd, &mut events.list, timeout_ms)?; + epoll::wait(&self.epoll_fd, &mut events.list, timeout_ms)?; tracing::trace!( epoll_fd = ?self.epoll_fd.as_raw_fd(), res = ?events.list.len(), @@ -310,10 +316,13 @@ impl Events { /// Iterates over I/O events. pub fn iter(&self) -> impl Iterator + '_ { - self.list.iter().map(|(flags, data)| Event { - key: data as usize, - readable: flags.intersects(read_flags()), - writable: flags.intersects(write_flags()), + self.list.iter().map(|ev| { + let flags = ev.flags; + Event { + key: ev.data.u64() as usize, + readable: flags.intersects(read_flags()), + writable: flags.intersects(write_flags()), + } }) } } diff --git a/src/kqueue.rs b/src/kqueue.rs index 7ec5559..62b7ea3 100644 --- a/src/kqueue.rs +++ b/src/kqueue.rs @@ -1,11 +1,11 @@ //! Bindings to kqueue (macOS, iOS, tvOS, watchOS, FreeBSD, NetBSD, OpenBSD, DragonFly BSD). use std::io; -use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, RawFd}; +use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, OwnedFd, RawFd}; use std::time::Duration; -use rustix::fd::OwnedFd; -use rustix::io::{fcntl_setfd, kqueue, Errno, FdFlags}; +use rustix::event::kqueue; +use rustix::io::{fcntl_setfd, Errno, FdFlags}; use crate::{Event, PollMode}; @@ -272,7 +272,7 @@ pub(crate) fn mode_to_flags(mode: PollMode) -> kqueue::EventFlags { ))] mod notify { use super::Poller; - use rustix::io::kqueue; + use rustix::event::kqueue; use std::io; use std::os::unix::io::BorrowedFd; @@ -429,7 +429,7 @@ mod notify { /// Whether this raw file descriptor is associated with this pipe. pub(super) fn has_fd(&self, fd: BorrowedFd<'_>) -> bool { - self.read_stream.as_raw_fd() == fd + self.read_stream.as_raw_fd() == fd.as_raw_fd() } } } diff --git a/src/lib.rs b/src/lib.rs index d76ff98..7903228 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -56,7 +56,7 @@ #![cfg(feature = "std")] #![cfg_attr(not(feature = "std"), no_std)] #![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)] -#![allow(clippy::useless_conversion, clippy::unnecessary_cast)] +#![allow(clippy::useless_conversion, clippy::unnecessary_cast, unused_unsafe)] #![cfg_attr(docsrs, feature(doc_cfg))] use std::fmt; @@ -302,7 +302,6 @@ impl Poller { /// poller.delete(&source)?; /// # std::io::Result::Ok(()) /// ``` - #[allow(unsafe_op_in_unsafe_fn)] pub unsafe fn add(&self, source: impl AsRawSource, interest: Event) -> io::Result<()> { self.add_with_mode(source, interest, PollMode::Oneshot) } diff --git a/src/os/kqueue.rs b/src/os/kqueue.rs index 8ea8729..684bd3e 100644 --- a/src/os/kqueue.rs +++ b/src/os/kqueue.rs @@ -7,7 +7,7 @@ use std::io; use std::process::Child; use std::time::Duration; -use rustix::io::kqueue; +use rustix::event::kqueue; use super::__private::PollerSealed; use __private::FilterSealed; @@ -238,7 +238,7 @@ unsafe impl FilterSealed for Timer { impl Filter for Timer {} mod __private { - use rustix::io::kqueue; + use rustix::event::kqueue; #[doc(hidden)] pub unsafe trait FilterSealed { diff --git a/src/poll.rs b/src/poll.rs index e70b472..1ecf278 100644 --- a/src/poll.rs +++ b/src/poll.rs @@ -7,12 +7,11 @@ use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; use std::sync::{Condvar, Mutex}; use std::time::{Duration, Instant}; +use rustix::event::{poll, PollFd, PollFlags}; use rustix::fd::{AsFd, AsRawFd, BorrowedFd, OwnedFd}; use rustix::fs::{fcntl_getfl, fcntl_setfl, OFlags}; -use rustix::io::{ - fcntl_getfd, fcntl_setfd, pipe, pipe_with, poll, read, write, FdFlags, PipeFlags, PollFd, - PollFlags, -}; +use rustix::io::{fcntl_getfd, fcntl_setfd, read, write, FdFlags}; +use rustix::pipe::{pipe, pipe_with, PipeFlags}; // std::os::unix doesn't exist on Fuchsia type RawFd = std::os::raw::c_int; diff --git a/src/port.rs b/src/port.rs index baa4cbf..bd55b15 100644 --- a/src/port.rs +++ b/src/port.rs @@ -4,8 +4,9 @@ use std::io; use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, RawFd}; use std::time::Duration; +use rustix::event::{port, PollFlags}; use rustix::fd::OwnedFd; -use rustix::io::{fcntl_getfd, fcntl_setfd, port, FdFlags, PollFlags}; +use rustix::io::{fcntl_getfd, fcntl_setfd, FdFlags}; use crate::{Event, PollMode};