Skip to content

Commit

Permalink
io: make duplex stream cooperative (tokio-rs#4470)
Browse files Browse the repository at this point in the history
Add coop checks on pipe poll_read and poll_write.

Fixes: tokio-rs#4470
Refs: tokio-rs#4291, tokio-rs#4300
  • Loading branch information
GongLG committed Feb 8, 2022
1 parent 40416b3 commit 26c26c4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions tokio/src/io/util/mem.rs
Expand Up @@ -245,7 +245,7 @@ impl AsyncRead for Pipe {

cfg_not_coop! {
fn poll_read(
mut self: Pin<&mut Self>,
self: Pin<&mut Self>,
cx: &mut task::Context<'_>,
buf: &mut ReadBuf<'_>,
) -> Poll<std::io::Result<()>> {
Expand Down Expand Up @@ -273,7 +273,7 @@ impl AsyncWrite for Pipe {

cfg_not_coop! {
fn poll_write(
mut self: Pin<&mut Self>,
self: Pin<&mut Self>,
cx: &mut task::Context<'_>,
buf: &[u8],
) -> Poll<std::io::Result<usize>> {
Expand Down
4 changes: 2 additions & 2 deletions tokio/tests/io_mem_stream.rs
Expand Up @@ -111,9 +111,9 @@ async fn duplex_is_cooperative() {
_ = async {
loop {
let buf = [3u8; 4096];
let _ = tx.write_all(&buf).await;
tx.write_all(&buf).await.unwrap();
let mut buf = [0u8; 4096];
let _ = rx.read(&mut buf).await;
rx.read(&mut buf).await.unwrap();
}
} => {},
_ = tokio::task::yield_now() => {}
Expand Down

0 comments on commit 26c26c4

Please sign in to comment.