rename feature and add changelog

This commit is contained in:
Rob Ede 2021-11-21 21:12:25 +00:00
parent 3dfa8b0faf
commit e9554bf851
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
6 changed files with 26 additions and 24 deletions

View File

@ -65,8 +65,8 @@ rustls = ["actix-http/rustls", "actix-tls/accept", "actix-tls/rustls"]
# Don't rely on these whatsoever. They may disappear at anytime. # Don't rely on these whatsoever. They may disappear at anytime.
__compress = [] __compress = []
# io-uring feature only avaiable for linux OS. # io-uring feature only avaiable for Linux OSes.
io-uring = ["actix-server/io-uring"] experimental-io-uring = ["actix-server/io-uring"]
[dependencies] [dependencies]
actix-codec = "0.4.1" actix-codec = "0.4.1"

View File

@ -1,8 +1,10 @@
# Changes # Changes
## Unreleased - 2021-xx-xx ## Unreleased - 2021-xx-xx
* Add crate feature `experimental-io-uring`, enabling async file I/O to be utilized. This feature is only available on Linux OSes with recent kernel versions. This feature is semver-exempt. [#2408]
* Fix 304 Not Modified responses to omit the Content-Length header, as per the spec. [#2453] * Fix 304 Not Modified responses to omit the Content-Length header, as per the spec. [#2453]
[#2408]: https://github.com/actix/actix-web/pull/2408
[#2453]: https://github.com/actix/actix-web/pull/2453 [#2453]: https://github.com/actix/actix-web/pull/2453

View File

@ -15,7 +15,7 @@ name = "actix_files"
path = "src/lib.rs" path = "src/lib.rs"
[features] [features]
io-uring = ["actix-web/io-uring", "tokio-uring"] experimental-io-uring = ["actix-web/experimental-io-uring", "tokio-uring"]
[dependencies] [dependencies]
actix-web = { version = "4.0.0-beta.11", default-features = false } actix-web = { version = "4.0.0-beta.11", default-features = false }

View File

@ -27,7 +27,7 @@ pin_project! {
} }
} }
#[cfg(not(feature = "io-uring"))] #[cfg(not(feature = "experimental-io-uring"))]
pin_project! { pin_project! {
#[project = ChunkedReadFileStateProj] #[project = ChunkedReadFileStateProj]
#[project_replace = ChunkedReadFileStateProjReplace] #[project_replace = ChunkedReadFileStateProjReplace]
@ -42,7 +42,7 @@ pin_project! {
} }
} }
#[cfg(feature = "io-uring")] #[cfg(feature = "experimental-io-uring")]
pin_project! { pin_project! {
#[project = ChunkedReadFileStateProj] #[project = ChunkedReadFileStateProj]
#[project_replace = ChunkedReadFileStateProjReplace] #[project_replace = ChunkedReadFileStateProjReplace]
@ -71,9 +71,9 @@ pub(crate) fn new_chunked_read(
ChunkedReadFile { ChunkedReadFile {
size, size,
offset, offset,
#[cfg(not(feature = "io-uring"))] #[cfg(not(feature = "experimental-io-uring"))]
state: ChunkedReadFileState::File { file: Some(file) }, state: ChunkedReadFileState::File { file: Some(file) },
#[cfg(feature = "io-uring")] #[cfg(feature = "experimental-io-uring")]
state: ChunkedReadFileState::File { state: ChunkedReadFileState::File {
file: Some((file, BytesMut::new())), file: Some((file, BytesMut::new())),
}, },
@ -82,7 +82,7 @@ pub(crate) fn new_chunked_read(
} }
} }
#[cfg(not(feature = "io-uring"))] #[cfg(not(feature = "experimental-io-uring"))]
async fn chunked_read_file_callback( async fn chunked_read_file_callback(
mut file: File, mut file: File,
offset: u64, offset: u64,
@ -109,7 +109,7 @@ async fn chunked_read_file_callback(
Ok(res) Ok(res)
} }
#[cfg(feature = "io-uring")] #[cfg(feature = "experimental-io-uring")]
async fn chunked_read_file_callback( async fn chunked_read_file_callback(
file: File, file: File,
offset: u64, offset: u64,
@ -129,7 +129,7 @@ async fn chunked_read_file_callback(
Ok((file, bytes, bytes_mut)) Ok((file, bytes, bytes_mut))
} }
#[cfg(feature = "io-uring")] #[cfg(feature = "experimental-io-uring")]
impl<F, Fut> Stream for ChunkedReadFile<F, Fut> impl<F, Fut> Stream for ChunkedReadFile<F, Fut>
where where
F: Fn(File, u64, usize, BytesMut) -> Fut, F: Fn(File, u64, usize, BytesMut) -> Fut,
@ -178,7 +178,7 @@ where
} }
} }
#[cfg(not(feature = "io-uring"))] #[cfg(not(feature = "experimental-io-uring"))]
impl<F, Fut> Stream for ChunkedReadFile<F, Fut> impl<F, Fut> Stream for ChunkedReadFile<F, Fut>
where where
F: Fn(File, u64, usize) -> Fut, F: Fn(File, u64, usize) -> Fut,
@ -226,12 +226,12 @@ where
} }
} }
#[cfg(feature = "io-uring")] #[cfg(feature = "experimental-io-uring")]
use bytes_mut::BytesMut; use bytes_mut::BytesMut;
// TODO: remove new type and use bytes::BytesMut directly // TODO: remove new type and use bytes::BytesMut directly
#[doc(hidden)] #[doc(hidden)]
#[cfg(feature = "io-uring")] #[cfg(feature = "experimental-io-uring")]
mod bytes_mut { mod bytes_mut {
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};

View File

@ -215,12 +215,12 @@ mod tests {
#[actix_rt::test] #[actix_rt::test]
async fn test_named_file_non_ascii_file_name() { async fn test_named_file_non_ascii_file_name() {
let file = { let file = {
#[cfg(feature = "io-uring")] #[cfg(feature = "experimental-io-uring")]
{ {
crate::named::File::open("Cargo.toml").await.unwrap() crate::named::File::open("Cargo.toml").await.unwrap()
} }
#[cfg(not(feature = "io-uring"))] #[cfg(not(feature = "experimental-io-uring"))]
{ {
crate::named::File::open("Cargo.toml").unwrap() crate::named::File::open("Cargo.toml").unwrap()
} }

View File

@ -88,11 +88,11 @@ impl fmt::Debug for NamedFile {
.field("path", &self.path) .field("path", &self.path)
.field( .field(
"file", "file",
#[cfg(feature = "io-uring")] #[cfg(feature = "experimental-io-uring")]
{ {
&"File" &"File"
}, },
#[cfg(not(feature = "io-uring"))] #[cfg(not(feature = "experimental-io-uring"))]
{ {
&self.file &self.file
}, },
@ -108,9 +108,9 @@ impl fmt::Debug for NamedFile {
} }
} }
#[cfg(not(feature = "io-uring"))] #[cfg(not(feature = "experimental-io-uring"))]
pub(crate) use std::fs::File; pub(crate) use std::fs::File;
#[cfg(feature = "io-uring")] #[cfg(feature = "experimental-io-uring")]
pub(crate) use tokio_uring::fs::File; pub(crate) use tokio_uring::fs::File;
impl NamedFile { impl NamedFile {
@ -183,12 +183,12 @@ impl NamedFile {
}; };
let md = { let md = {
#[cfg(not(feature = "io-uring"))] #[cfg(not(feature = "experimental-io-uring"))]
{ {
file.metadata()? file.metadata()?
} }
#[cfg(feature = "io-uring")] #[cfg(feature = "experimental-io-uring")]
{ {
use std::os::unix::prelude::{AsRawFd, FromRawFd}; use std::os::unix::prelude::{AsRawFd, FromRawFd};
@ -220,7 +220,7 @@ impl NamedFile {
}) })
} }
#[cfg(not(feature = "io-uring"))] #[cfg(not(feature = "experimental-io-uring"))]
/// Attempts to open a file in read-only mode. /// Attempts to open a file in read-only mode.
/// ///
/// # Examples /// # Examples
@ -248,12 +248,12 @@ impl NamedFile {
/// ``` /// ```
pub async fn open_async<P: AsRef<Path>>(path: P) -> io::Result<NamedFile> { pub async fn open_async<P: AsRef<Path>>(path: P) -> io::Result<NamedFile> {
let file = { let file = {
#[cfg(not(feature = "io-uring"))] #[cfg(not(feature = "experimental-io-uring"))]
{ {
File::open(&path)? File::open(&path)?
} }
#[cfg(feature = "io-uring")] #[cfg(feature = "experimental-io-uring")]
{ {
File::open(&path).await? File::open(&path).await?
} }