Skip to content

Commit

Permalink
Fix incorrect use of clear_ready
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 c9e20e6 commit ad7f1a8
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,16 @@ async fn tee_impl(pipe_in: &PipeRead, pipe_out: &PipeWrite, len: usize) -> io::R
let mut read_ready = pipe_in.0.readable().await?;
let mut write_ready = pipe_out.0.writable().await?;

read_ready.clear_ready();
write_ready.clear_ready();

loop {
let ret = unsafe { libc::tee(fd_in, fd_out, len, libc::SPLICE_F_NONBLOCK) };
match cvt!(ret) {
Err(e) if is_wouldblock(&e) => (),
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?;
}
Err(e) => break Err(e),
Ok(ret) => break Ok(ret as usize),
}
Expand Down Expand Up @@ -264,23 +267,24 @@ async fn splice_impl(
let fd_in = asyncfd_in.as_raw_fd();
let fd_out = asyncfd_out.as_raw_fd();

let off_in = as_ptr(off_in);
let off_out = as_ptr(off_out);

let flags = libc::SPLICE_F_NONBLOCK
| if has_more_data {
libc::SPLICE_F_MORE
} else {
0
};

read_ready.clear_ready();
write_ready.clear_ready();

loop {
let ret = unsafe { libc::splice(fd_in, off_in, fd_out, off_out, len, flags) };
let ret =
unsafe { libc::splice(fd_in, as_ptr(off_in), fd_out, as_ptr(off_out), len, flags) };
match cvt!(ret) {
Err(e) if is_wouldblock(&e) => (),
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?;
}
Err(e) => break Err(e),
Ok(ret) => break Ok(ret as usize),
}
Expand Down

0 comments on commit ad7f1a8

Please sign in to comment.