Skip to content

Commit

Permalink
feat(files): remove block on, as it does more harm than good here
Browse files Browse the repository at this point in the history
  • Loading branch information
joelwurtz committed Dec 13, 2024
1 parent 8115c81 commit d292546
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
1 change: 1 addition & 0 deletions actix-files/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- Minimum supported Rust version (MSRV) is now 1.75.
- Avoid spawning a thread for each file which does more harm than good

## 0.6.6

Expand Down
21 changes: 8 additions & 13 deletions actix-files/src/chunked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,17 @@ async fn chunked_read_file_callback(
) -> Result<(File, Bytes), Error> {
use io::{Read as _, Seek as _};

let res = actix_web::web::block(move || {
let mut buf = Vec::with_capacity(max_bytes);
let mut buf = Vec::with_capacity(max_bytes);

file.seek(io::SeekFrom::Start(offset))?;
file.seek(io::SeekFrom::Start(offset))?;

let n_bytes = file.by_ref().take(max_bytes as u64).read_to_end(&mut buf)?;
let n_bytes = file.by_ref().take(max_bytes as u64).read_to_end(&mut buf)?;

if n_bytes == 0 {
Err(io::Error::from(io::ErrorKind::UnexpectedEof))
} else {
Ok((file, Bytes::from(buf)))
}
})
.await??;

Ok(res)
if n_bytes == 0 {
Err(Error::from(io::Error::from(io::ErrorKind::UnexpectedEof)))
} else {
Ok((file, Bytes::from(buf)))
}
}

#[cfg(feature = "experimental-io-uring")]
Expand Down

0 comments on commit d292546

Please sign in to comment.