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

try_read_vectored and try_write_vectored use default implementations that only process the first buffer #6970

Open
tomashaddad opened this issue Nov 13, 2024 · 1 comment
Labels
A-tokio Area: The main tokio crate C-bug Category: This is a bug. M-net Module: tokio/net

Comments

@tomashaddad
Copy link

Version
1.41.1

Platform
64-bit (Windows)

Description
I was using NamedPipeClient's try_write_vectored exactly as detailed in the documentation but noticed that only the first buffer would ever be written. Looking under the hood, it seems to be using the default implementation from std::io::Write, sans an important caveat in the rustdocs:

The default implementation calls write with either the first nonempty buffer provided, or an empty one if none exists.

i.e.,

pub(crate) fn default_read_vectored<F>(read: F, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
where
    F: FnOnce(&mut [u8]) -> Result<usize>,
{
    let buf = bufs.iter_mut().find(|b| !b.is_empty()).map_or(&mut [][..], |b| &mut **b);
    read(buf)
}

Are these meant to be properly implemented?

@tomashaddad tomashaddad added A-tokio Area: The main tokio crate C-bug Category: This is a bug. labels Nov 13, 2024
@Darksonn Darksonn added the M-net Module: tokio/net label Nov 13, 2024
@Darksonn
Copy link
Contributor

Thanks for reporting this. Yes, we would like these methods to actually perform a vectored read.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-bug Category: This is a bug. M-net Module: tokio/net
Projects
None yet
Development

No branches or pull requests

2 participants