Skip to content

Commit

Permalink
Fix typo in splice_impl and tee_impl
Browse files Browse the repository at this point in the history
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
  • Loading branch information
NobodyXu committed Jun 21, 2022
1 parent ad7f1a8 commit 6dc30ea
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,19 @@ impl<'a, 'b> AtomicWriteIoSlices<'a, 'b> {

#[cfg(target_os = "linux")]
async fn tee_impl(pipe_in: &PipeRead, pipe_out: &PipeWrite, len: usize) -> io::Result<usize> {
let fd_in = pipe_in.0.as_raw_fd();
let fd_out = pipe_out.0.as_raw_fd();

// There is only one reader and one writer, so it only needs to polled once.
let mut read_ready = pipe_in.0.readable().await?;
let mut write_ready = pipe_out.0.writable().await?;

loop {
let ret = unsafe { libc::tee(fd_in, fd_out, len, libc::SPLICE_F_NONBLOCK) };
let ret = unsafe {
libc::tee(
pipe_in.as_raw_fd(),
pipe_out.as_raw_fd(),
len,
libc::SPLICE_F_NONBLOCK,
)
};
match cvt!(ret) {
Err(e) if is_wouldblock(&e) => {
read_ready.clear_ready();
Expand Down Expand Up @@ -252,21 +256,18 @@ fn as_ptr<T>(option: Option<&mut T>) -> *mut T {

#[cfg(target_os = "linux")]
async fn splice_impl(
asyncfd_in: &mut AsyncFd<impl AsRawFd>,
fd_in: &mut AsyncFd<impl AsRawFd>,
off_in: Option<&mut off64_t>,
asyncfd_out: &AsyncFd<impl AsRawFd>,
fd_out: &AsyncFd<impl AsRawFd>,
off_out: Option<&mut off64_t>,
len: usize,
has_more_data: bool,
) -> io::Result<usize> {
// There is only one reader and one writer, so it only needs to polled once.
let mut read_ready = asyncfd_in.readable().await?;
let mut write_ready = asyncfd_out.writable().await?;
let mut read_ready = fd_in.readable().await?;
let mut write_ready = fd_out.writable().await?;

// Prepare args for the syscall
let fd_in = asyncfd_in.as_raw_fd();
let fd_out = asyncfd_out.as_raw_fd();

let flags = libc::SPLICE_F_NONBLOCK
| if has_more_data {
libc::SPLICE_F_MORE
Expand All @@ -275,15 +276,23 @@ async fn splice_impl(
};

loop {
let ret =
unsafe { libc::splice(fd_in, as_ptr(off_in), fd_out, as_ptr(off_out), len, flags) };
let ret = unsafe {
libc::splice(
fd_in.as_raw_fd(),
as_ptr(off_in),
fd_out.as_raw_fd(),
as_ptr(off_out),
len,
flags,
)
};
match cvt!(ret) {
Err(e) if is_wouldblock(&e) => {
read_ready.clear_ready();
write_ready.clear_ready();

read_ready = pipe_in.0.readable().await?;
write_ready = pipe_out.0.writable().await?;
read_ready = fd_in.0.readable().await?;
write_ready = fd_out.0.writable().await?;
}
Err(e) => break Err(e),
Ok(ret) => break Ok(ret as usize),
Expand Down

0 comments on commit 6dc30ea

Please sign in to comment.