diff options
author | Frederick Mayle <fmayle@google.com> | 2024-04-09 14:00:15 -0700 |
---|---|---|
committer | Frederick Mayle <fmayle@google.com> | 2024-04-10 13:08:38 -0700 |
commit | ac496a90aa2231bded469eb195732c05336e2cad (patch) | |
tree | 0ee864f92732f2152491b53a52bd111541482fe3 | |
parent | dd5d06c75fc91d30e7544daffe6fae5d0e31b9ea (diff) | |
download | tokio-master.tar.gz |
Not possible to make this change upstream yet, see
https://github.com/tokio-rs/tokio/pull/6474.
Bug: 333427576
Test: TreeHugger
Change-Id: I950e3e7efc41e0e8e23db373ff918d11a4362359
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | Cargo.toml.orig | 2 | ||||
-rw-r--r-- | patches/nix_0.28.patch | 113 | ||||
-rw-r--r-- | tests/io_async_fd.rs | 31 |
4 files changed, 124 insertions, 24 deletions
@@ -208,7 +208,7 @@ optional = true version = "0.2.149" [target."cfg(unix)".dev-dependencies.nix] -version = "0.27.1" +version = "0.28.0" features = [ "fs", "socket", diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 069bb13..91fc426 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -123,7 +123,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.28.0", default-features = false, features = ["fs", "socket"] } [target.'cfg(windows)'.dependencies.windows-sys] version = "0.48" diff --git a/patches/nix_0.28.patch b/patches/nix_0.28.patch new file mode 100644 index 0000000..34c2f39 --- /dev/null +++ b/patches/nix_0.28.patch @@ -0,0 +1,113 @@ +diff --git a/Cargo.toml b/Cargo.toml +index 6728a901..5291a632 100644 +--- a/Cargo.toml ++++ b/Cargo.toml +@@ -208,7 +208,7 @@ optional = true + version = "0.2.149" + + [target."cfg(unix)".dev-dependencies.nix] +-version = "0.27.1" ++version = "0.28.0" + features = [ + "fs", + "socket", +diff --git a/Cargo.toml.orig b/Cargo.toml.orig +index 069bb130..91fc4261 100644 +--- a/Cargo.toml.orig ++++ b/Cargo.toml.orig +@@ -123,7 +123,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.28.0", default-features = false, features = ["fs", "socket"] } + + [target.'cfg(windows)'.dependencies.windows-sys] + version = "0.48" +diff --git a/tests/io_async_fd.rs b/tests/io_async_fd.rs +index 49b5a683..aca25462 100644 +--- a/tests/io_async_fd.rs ++++ b/tests/io_async_fd.rs +@@ -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; + +@@ -57,18 +57,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) + } + } + +@@ -80,7 +80,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<()> { +@@ -98,12 +98,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}; + +@@ -132,17 +126,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 + } diff --git a/tests/io_async_fd.rs b/tests/io_async_fd.rs index 49b5a68..aca2546 100644 --- a/tests/io_async_fd.rs +++ b/tests/io_async_fd.rs @@ -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; @@ -57,18 +57,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) } } @@ -80,7 +80,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<()> { @@ -98,12 +98,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}; @@ -132,17 +126,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 } |