Skip to content

Commit

Permalink
double check Reader waker
Browse files Browse the repository at this point in the history
  • Loading branch information
zonyitoo committed May 6, 2022
1 parent 2c28526 commit 3e23d00
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
12 changes: 9 additions & 3 deletions src/sys/unix/bsd/freebsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ impl AsyncRead for TcpStream {
TcpStreamOptionProj::Connected(stream) => stream.poll_read(cx, buf),
TcpStreamOptionProj::Connecting { reader, .. } => {
if let Some(w) = reader.take() {
w.wake();
if !w.will_wake(cx.waker()) {
w.wake();
}
}
*reader = Some(cx.waker().clone());
Poll::Pending
Expand Down Expand Up @@ -233,7 +235,9 @@ impl AsyncWrite for TcpStream {

// Wake up the Future that pending on poll_read
if let Some(w) = reader.take() {
w.wake();
if !w.will_wake(cx.waker()) {
w.wake();
}
}

return Ok(ret as usize).into();
Expand Down Expand Up @@ -265,7 +269,9 @@ impl AsyncWrite for TcpStream {

// Wake up the Future that pending on poll_read
if let Some(w) = reader.take() {
w.wake();
if !w.will_wake(cx.waker()) {
w.wake();
}
}
} else {
// Other errors, including EAGAIN, EWOULDBLOCK
Expand Down
12 changes: 9 additions & 3 deletions src/sys/unix/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ impl AsyncRead for TcpStream {
TcpStreamOptionProj::Connected(stream) => stream.poll_read(cx, buf),
TcpStreamOptionProj::Connecting { reader, .. } => {
if let Some(w) = reader.take() {
w.wake();
if !w.will_wake(cx.waker()) {
w.wake();
}
}
*reader = Some(cx.waker().clone());
Poll::Pending
Expand Down Expand Up @@ -258,7 +260,9 @@ impl AsyncWrite for TcpStream {

// Wake up the Future that pending on poll_read
if let Some(w) = reader.take() {
w.wake();
if !w.will_wake(cx.waker()) {
w.wake();
}
}

return Ok(ret as usize).into();
Expand Down Expand Up @@ -290,7 +294,9 @@ impl AsyncWrite for TcpStream {

// Wake up the Future that pending on poll_read
if let Some(w) = reader.take() {
w.wake();
if !w.will_wake(cx.waker()) {
w.wake();
}
}
} else {
// Other errors, including EAGAIN, EWOULDBLOCK
Expand Down
12 changes: 9 additions & 3 deletions src/sys/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ impl AsyncRead for TcpStream {
TcpStreamOptionProj::Connected(stream) => stream.poll_read(cx, buf),
TcpStreamOptionProj::Connecting { reader, .. } => {
if let Some(w) = reader.take() {
w.wake();
if !w.will_wake(cx.waker()) {
w.wake();
}
}
*reader = Some(cx.waker().clone());
Poll::Pending
Expand Down Expand Up @@ -355,7 +357,9 @@ impl AsyncWrite for TcpStream {

// Wake up the Future that pending on poll_read
if let Some(w) = reader.take() {
w.wake();
if !w.will_wake(cx.waker()) {
w.wake();
}
}

return Ok(bytes_sent as usize).into();
Expand All @@ -382,7 +386,9 @@ impl AsyncWrite for TcpStream {

// Wake up the Future that pending on poll_read
if let Some(w) = reader.take() {
w.wake();
if !w.will_wake(cx.waker()) {
w.wake();
}
}
}
}
Expand Down

0 comments on commit 3e23d00

Please sign in to comment.