Skip to content

Commit 72afa2b

Browse files
mmirateEugeny
authored andcommitted
Eliminate busywaiting in ChannelRx
1 parent a904a08 commit 72afa2b

File tree

1 file changed

+4
-11
lines changed
  • russh/src/channels/io

1 file changed

+4
-11
lines changed

russh/src/channels/io/rx.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use std::io;
22
use std::pin::Pin;
3-
use std::task::{Context, Poll};
3+
use std::task::{Context, Poll, ready};
44

55
use tokio::io::AsyncRead;
6-
use tokio::sync::mpsc::error::TryRecvError;
76

87
use super::{ChannelAsMut, ChannelMsg};
98
use crate::ChannelId;
@@ -43,15 +42,9 @@ where
4342
) -> Poll<io::Result<()>> {
4443
let (msg, mut idx) = match self.buffer.take() {
4544
Some(msg) => msg,
46-
None => match self.channel.as_mut().receiver.try_recv() {
47-
Ok(msg) => (msg, 0),
48-
Err(TryRecvError::Empty) => {
49-
cx.waker().wake_by_ref();
50-
return Poll::Pending;
51-
}
52-
Err(TryRecvError::Disconnected) => {
53-
return Poll::Ready(Ok(()));
54-
}
45+
None => match ready!(self.channel.as_mut().receiver.poll_recv(cx)) {
46+
Some(msg) => (msg, 0),
47+
None => return Poll::Ready(Ok(())),
5548
},
5649
};
5750

0 commit comments

Comments
 (0)