Where to get num_bytes_read
from, when using new AsyncRead::poll_read
?
#2990
-
Hello, it's me again 😸 If one was previously using the Actually the docs still says it would be returned, but as far as I get the function signature it is not... (trait.AsyncRead.poll_read). Corresponding code: https://github.com/snapview/tokio-tungstenite/blob/master/src/compat.rs#L142-L160 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Is it possible to just call fn run(a: impl AsyncRead, b: &mut [u8], c: &mut Context) -> usize {
let mut read_buf = ReadBuf::new(b);
let before = read_buf.remaining();
a.poll_read(c, &mut read_buf);
let num_bytes_read = before - read_buf.remaining();
num_bytes_read
} Should this work or am I missing something? |
Beta Was this translation helpful? Give feedback.
-
Since you created the tokio/tokio-util/src/io/poll_read_buf.rs Lines 59 to 63 in 8d17261 |
Beta Was this translation helpful? Give feedback.
Since you created the
ReadBuf
, you know that it starts withfilled()
empty. Thus, the number of bytes can be obtained withread_buf.filled().len()
after callingpoll_read
. You may enjoy this snippet:tokio/tokio-util/src/io/poll_read_buf.rs
Lines 59 to 63 in 8d17261