From fa5c9dc8cc57d2678f7c4632af5f79d7a8619d49 Mon Sep 17 00:00:00 2001 From: oech3 <79379754+oech3@users.noreply.github.com> Date: Sun, 26 Apr 2026 20:05:40 +0900 Subject: [PATCH] extend pipe size if possible --- src/main.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index d4bf114..21d1938 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,23 +13,25 @@ use std::fs::File; use std::io; use std::os::unix::io::{AsRawFd, RawFd}; -use nix::fcntl::{splice, SpliceFFlags}; +use nix::fcntl::{fcntl, FcntlArg, splice, SpliceFFlags}; use nix::unistd::pipe; -const BUF_SIZE: usize = 16384; +const MAX_ROOTLESS_PIPE_SIZE: usize = 1024 * 1024; #[inline] fn cat(input: &T, pipe_rd: RawFd, pipe_wr: RawFd) { let stdout = io::stdout(); let _handle = stdout.lock(); + let _ = fcntl(pipe_wr, FcntlArg::F_SETPIPE_SZ(MAX_ROOTLESS_PIPE_SIZE as i32)); + loop { let res = splice( input.as_raw_fd(), None, pipe_wr, None, - BUF_SIZE, + MAX_ROOTLESS_PIPE_SIZE, SpliceFFlags::empty(), ) .unwrap(); @@ -45,7 +47,7 @@ fn cat(input: &T, pipe_rd: RawFd, pipe_wr: RawFd) { None, stdout.as_raw_fd(), None, - BUF_SIZE, + MAX_ROOTLESS_PIPE_SIZE, SpliceFFlags::empty(), ) .unwrap();