Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add mutable buffer api to FramedRead #3166

Merged
merged 1 commit into from
Nov 24, 2020

Conversation

driftluo
Copy link
Contributor

fix #3165

Can this PR also be patched to the 0.3.x version of tokio-util?

@Darksonn Darksonn added A-tokio-util Area: The tokio-util crate C-enhancement Category: A PR with an enhancement or bugfix. M-codec Module: tokio-util/codec labels Nov 23, 2020
@Darksonn
Copy link
Contributor

If you want this to be added to the v0.3.x version of tokio-util too, then please submit a backport PR as well. You will need to base your branch off the v0.2.x branch as tokio-util 0.3 is on the Tokio 0.2 branch.

@driftluo
Copy link
Contributor Author

driftluo commented Nov 24, 2020

If you want this to be added to the v0.3.x version of tokio-util too, then please submit a backport PR as well. You will need to base your branch off the v0.2.x branch as tokio-util 0.3 is on the Tokio 0.2 branch.

I bypassed this problem with the new type and don't need a patch if the 0.3 util is not needed for release new version, like it:

pub(crate) struct PatchedReadPart {
    buffer: bytes::BytesMut,
    io: ReadHalf<io>,
}

impl AsyncRead for PatchedReadPart {
    fn poll_read(
        mut self: Pin<&mut Self>,
        cx: &mut Context<'_>,
        buf: &mut [u8],
    ) -> Poll<io::Result<usize>> {
        if self.buffer.is_empty() {
            Pin::new(&mut self.io).poll_read(cx, buf)
        } else {
            let n = ::std::cmp::min(buf.len(), self.buffer.len());
            let b = self.buffer.split_to(n);
            buf[..n].copy_from_slice(&b);
            Poll::Ready(Ok(n))
        }
    }
}

@Darksonn Darksonn merged commit 874fc33 into tokio-rs:master Nov 24, 2020
@driftluo driftluo deleted the add-mut-buffer-to-framtedread branch November 24, 2020 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio-util Area: The tokio-util crate C-enhancement Category: A PR with an enhancement or bugfix. M-codec Module: tokio-util/codec
Projects
None yet
Development

Successfully merging this pull request may close these issues.

util: FramedRead api
2 participants