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

DuplexStream does not support vectored writes #5983

Closed
qrnch-jan opened this issue Sep 5, 2023 · 0 comments
Closed

DuplexStream does not support vectored writes #5983

qrnch-jan opened this issue Sep 5, 2023 · 0 comments
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-io Module: tokio/io

Comments

@qrnch-jan
Copy link
Contributor

qrnch-jan commented Sep 5, 2023

When write_vectored is used on a DuplexStream it only writes the first buffer in the scatter/gather list.

It would be nice if it wrote as much as it can.

The following code illustrates the problem:

use std::io::IoSlice;
use bytes::Bytes;
use tokio::io::AsyncWriteExt;

#[tokio::main]
async fn main() {
    let bufs = vec![Bytes::from("hello,"), Bytes::from(" world")];
    let (mut ep1, _ep2) = tokio::io::duplex(64*1024);
    let iov: Vec<IoSlice> = bufs.iter().map(|b| IoSlice::new(b)).collect();
    println!("iov.len={}", iov.len());
    let total_size = iov.iter().fold(0, |acc, e| acc + e.len());
    println!("total size: {}", total_size);
    let written = ep1.write_vectored(&iov[..]).await.unwrap();
    println!("wrote {} bytes", written)
}

The program outputs that it has written 6 bytes, rather than the expected 12.

@qrnch-jan qrnch-jan added A-tokio Area: The main tokio crate C-feature-request Category: A feature request. labels Sep 5, 2023
@Darksonn Darksonn closed this as completed Sep 8, 2023
@Darksonn Darksonn added the M-io Module: tokio/io label Sep 8, 2023
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-feature-request Category: A feature request. M-io Module: tokio/io
Projects
None yet
Development

No branches or pull requests

2 participants