Skip to content

Commit

Permalink
Bump to rustix v0.38
Browse files Browse the repository at this point in the history
  • Loading branch information
notgull committed Jun 29, 2023
1 parent c04057e commit 3ecd41f
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 41 deletions.
15 changes: 0 additions & 15 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
31 changes: 20 additions & 11 deletions src/epoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)?;
Expand Down Expand Up @@ -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),
)?;

Expand All @@ -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(())
}
Expand All @@ -135,7 +141,7 @@ impl Poller {
);
let _enter = span.enter();

epoll::epoll_del(&self.epoll_fd, fd)?;
epoll::delete(&self.epoll_fd, fd)?;

Ok(())
}
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -310,10 +316,13 @@ impl Events {

/// Iterates over I/O events.
pub fn iter(&self) -> impl Iterator<Item = Event> + '_ {
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()),
}
})
}
}
10 changes: 5 additions & 5 deletions src/kqueue.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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()
}
}
}
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions src/os/kqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 3 additions & 4 deletions src/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down

0 comments on commit 3ecd41f

Please sign in to comment.