Skip to content

Commit

Permalink
Eliminate busywaiting in ChannelRx
Browse files Browse the repository at this point in the history
  • Loading branch information
mmirate authored and Eugeny committed Nov 1, 2023
1 parent a904a08 commit 72afa2b
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions russh/src/channels/io/rx.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::io;
use std::pin::Pin;
use std::task::{Context, Poll};
use std::task::{Context, Poll, ready};

use tokio::io::AsyncRead;
use tokio::sync::mpsc::error::TryRecvError;

use super::{ChannelAsMut, ChannelMsg};
use crate::ChannelId;
Expand Down Expand Up @@ -43,15 +42,9 @@ where
) -> Poll<io::Result<()>> {
let (msg, mut idx) = match self.buffer.take() {
Some(msg) => msg,
None => match self.channel.as_mut().receiver.try_recv() {
Ok(msg) => (msg, 0),
Err(TryRecvError::Empty) => {
cx.waker().wake_by_ref();
return Poll::Pending;
}
Err(TryRecvError::Disconnected) => {
return Poll::Ready(Ok(()));
}
None => match ready!(self.channel.as_mut().receiver.poll_recv(cx)) {
Some(msg) => (msg, 0),
None => return Poll::Ready(Ok(())),
},
};

Expand Down

0 comments on commit 72afa2b

Please sign in to comment.