Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/uu/cat/src/splice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub(super) fn write_fast_using_splice<R: FdReadable, S: AsRawFd + AsFd>(
handle: &InputHandle<R>,
write_fd: &S,
) -> CatResult<bool> {
use std::{fs::File, sync::OnceLock};
static BROKER: OnceLock<Option<(File, File)>> = OnceLock::new();
if splice(&handle.reader, &write_fd, MAX_ROOTLESS_PIPE_SIZE).is_ok() {
// fcntl improves throughput
// todo: avoid fcntl overhead for small input, but don't fcntl inside of the loop
Expand All @@ -34,7 +36,7 @@ pub(super) fn write_fast_using_splice<R: FdReadable, S: AsRawFd + AsFd>(
Err(_) => return Ok(true),
}
}
} else if let Ok((pipe_rd, pipe_wr)) = pipe() {
} else if let Some((pipe_rd, pipe_wr)) = BROKER.get_or_init(|| pipe().ok()).as_ref() {
// both of in/output are not pipe. needs broker to use splice() with additional costs
loop {
match splice(&handle.reader, &pipe_wr, MAX_ROOTLESS_PIPE_SIZE) {
Expand Down
Loading