Skip to content

Commit

Permalink
Eliminate busywaiting in ChannelRx
Browse files Browse the repository at this point in the history
  • Loading branch information
mmirate committed Oct 27, 2023
1 parent 02899e9 commit 5defc91
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 5defc91

Please sign in to comment.