tests: update nix and mio-aio dependencies (#6552)

nix 0.29.0 and mio-aio 0.9.0 use I/O Safety.

Co-authored-by: Frederick Mayle <fmayle@google.com>
This commit is contained in:
Alan Somers 2024-05-25 09:30:36 -06:00 committed by GitHub
parent cba86cf1b1
commit 12920cea45
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 19 additions and 34 deletions

View File

@ -17,4 +17,3 @@ members = [
[workspace.metadata.spellcheck]
config = "spellcheck.toml"

View File

@ -118,7 +118,7 @@ signal-hook-registry = { version = "1.1.1", optional = true }
[target.'cfg(unix)'.dev-dependencies]
libc = { version = "0.2.149" }
nix = { version = "0.27.1", default-features = false, features = ["fs", "socket"] }
nix = { version = "0.29.0", default-features = false, features = ["aio", "fs", "socket"] }
[target.'cfg(windows)'.dependencies.windows-sys]
version = "0.48"
@ -149,7 +149,7 @@ rand = "0.8.0"
wasm-bindgen-test = "0.3.0"
[target.'cfg(target_os = "freebsd")'.dev-dependencies]
mio-aio = { version = "0.8.0", features = ["tokio"] }
mio-aio = { version = "0.9.0", features = ["tokio"] }
[target.'cfg(loom)'.dev-dependencies]
loom = { version = "0.7", features = ["futures", "checkpoint"] }

View File

@ -1,7 +1,7 @@
#![warn(rust_2018_idioms)]
#![cfg(all(unix, feature = "full"))]
use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd};
use std::os::unix::io::{AsRawFd, RawFd};
use std::sync::{
atomic::{AtomicBool, Ordering},
Arc,
@ -13,7 +13,7 @@ use std::{
task::{Context, Waker},
};
use nix::unistd::{close, read, write};
use nix::unistd::{read, write};
use futures::poll;
@ -58,18 +58,18 @@ impl TestWaker {
#[derive(Debug)]
struct FileDescriptor {
fd: RawFd,
fd: std::os::fd::OwnedFd,
}
impl AsRawFd for FileDescriptor {
fn as_raw_fd(&self) -> RawFd {
self.fd
self.fd.as_raw_fd()
}
}
impl Read for &FileDescriptor {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
read(self.fd, buf).map_err(io::Error::from)
read(self.fd.as_raw_fd(), buf).map_err(io::Error::from)
}
}
@ -81,7 +81,7 @@ impl Read for FileDescriptor {
impl Write for &FileDescriptor {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
write(self.fd, buf).map_err(io::Error::from)
write(&self.fd, buf).map_err(io::Error::from)
}
fn flush(&mut self) -> io::Result<()> {
@ -99,12 +99,6 @@ impl Write for FileDescriptor {
}
}
impl Drop for FileDescriptor {
fn drop(&mut self) {
let _ = close(self.fd);
}
}
fn set_nonblocking(fd: RawFd) {
use nix::fcntl::{OFlag, F_GETFL, F_SETFL};
@ -133,17 +127,10 @@ fn socketpair() -> (FileDescriptor, FileDescriptor) {
SockFlag::empty(),
)
.expect("socketpair");
let fds = (
FileDescriptor {
fd: fd_a.into_raw_fd(),
},
FileDescriptor {
fd: fd_b.into_raw_fd(),
},
);
let fds = (FileDescriptor { fd: fd_a }, FileDescriptor { fd: fd_b });
set_nonblocking(fds.0.fd);
set_nonblocking(fds.1.fd);
set_nonblocking(fds.0.fd.as_raw_fd());
set_nonblocking(fds.1.fd.as_raw_fd());
fds
}

View File

@ -5,6 +5,7 @@ use mio_aio::{AioFsyncMode, SourceApi};
use std::{
future::Future,
io, mem,
os::fd::AsFd,
os::unix::io::{AsRawFd, RawFd},
pin::{pin, Pin},
task::{Context, Poll},
@ -17,9 +18,9 @@ mod aio {
use super::*;
#[derive(Debug)]
struct TokioSource(mio_aio::Source<nix::sys::aio::AioFsync>);
struct TokioSource<'fd>(mio_aio::Source<nix::sys::aio::AioFsync<'fd>>);
impl AioSource for TokioSource {
impl<'fd> AioSource for TokioSource<'fd> {
fn register(&mut self, kq: RawFd, token: usize) {
self.0.register_raw(kq, token)
}
@ -29,9 +30,9 @@ mod aio {
}
/// A very crude implementation of an AIO-based future
struct FsyncFut(Aio<TokioSource>);
struct FsyncFut<'fd>(Aio<TokioSource<'fd>>);
impl FsyncFut {
impl<'fd> FsyncFut<'fd> {
pub fn submit(self: Pin<&mut Self>) -> io::Result<()> {
let p = unsafe { self.map_unchecked_mut(|s| &mut s.0 .0) };
match p.submit() {
@ -41,7 +42,7 @@ mod aio {
}
}
impl Future for FsyncFut {
impl<'fd> Future for FsyncFut<'fd> {
type Output = io::Result<()>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
@ -134,7 +135,7 @@ mod aio {
#[tokio::test]
async fn fsync() {
let f = tempfile().unwrap();
let fd = f.as_raw_fd();
let fd = f.as_fd();
let mode = AioFsyncMode::O_SYNC;
let source = TokioSource(mio_aio::Fsync::fsync(fd, mode, 0));
let poll_aio = Aio::new_for_aio(source).unwrap();

View File

@ -489,12 +489,10 @@ async fn anon_pipe_spawn_echo() -> std::io::Result<()> {
#[cfg(target_os = "linux")]
async fn anon_pipe_from_owned_fd() -> std::io::Result<()> {
use nix::fcntl::OFlag;
use std::os::unix::io::{FromRawFd, OwnedFd};
const DATA: &[u8] = b"this is some data to write to the pipe";
let fds = nix::unistd::pipe2(OFlag::O_CLOEXEC | OFlag::O_NONBLOCK)?;
let (rx_fd, tx_fd) = unsafe { (OwnedFd::from_raw_fd(fds.0), OwnedFd::from_raw_fd(fds.1)) };
let (rx_fd, tx_fd) = nix::unistd::pipe2(OFlag::O_CLOEXEC | OFlag::O_NONBLOCK)?;
let mut rx = pipe::Receiver::from_owned_fd(rx_fd)?;
let mut tx = pipe::Sender::from_owned_fd(tx_fd)?;