Will tokio ever pass a ReadBuf with no capacity to poll_read()?

While implementing a Base64-decoding implementation of AsyncRead (does this already exist, BTW?) I realized I don't know whether the ReadBuf passed to poll_read() can ever be full. In other words, is this assertion safe:

    fn poll_read(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>,
        rd_buf: &mut tokio::io::ReadBuf<'_>,
    ) -> Poll<std::io::Result<()>> {
        // I think this is impossible, although I couldn't find docs.
        assert!(rd_buf.remaining() > 0);
        // ....
    }

It feels like tokio would never pass a full ReadBuf, because what would be the point? I just want to be sure.

It can happen, but you should just return Ready(Ok(())) without doing anything.

Fair enough, but the docs for AsyncRead say that returning Poll::Ready(Ok(())) without adding data to the ReadBuf signals EOF. I don't want to signal EOF

We should clarify that. You may file a documentation bug. It's similar to std Read which also has an exception for EOF in the empty buffer case.

1 Like

Will do, thanks

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.