Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
transports/tcp/src/lib: Bridge between tokio and futures AsyncRead
  • Loading branch information
mxinden committed Oct 16, 2020
commit 77de17cc49eaafdb727318f222283997dd921d35
1 change: 1 addition & 0 deletions protocols/mdns/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ wasm-timer = "0.2.4"

[dev-dependencies]
if-addrs = "0.6.4"
tokio = { version = "0.3", default-features = false, features = ["rt", "rt-multi-thread"] }
5 changes: 4 additions & 1 deletion transports/tcp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,10 @@ impl AsyncWrite for TcpTransStream {
#[cfg(feature = "tokio")]
impl AsyncRead for TokioTcpTransStream {
fn poll_read(mut self: Pin<&mut Self>, cx: &mut Context, buf: &mut [u8]) -> Poll<Result<usize, io::Error>> {
tokio::io::AsyncRead::poll_read(Pin::new(&mut self.inner), cx, buf)
// TODO: Put more thoughts into this.
let mut read_buf = tokio::io::ReadBuf::new(buf);
let result = futures::ready!(tokio::io::AsyncRead::poll_read(Pin::new(&mut self.inner), cx, &mut read_buf));
Poll::Ready(result.map(|()| read_buf.filled().len()))
}
}

Expand Down