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

Trait AsyncVectoredWrite and related utilities #3092

Closed
wants to merge 14 commits into from

Conversation

mzabaluev
Copy link
Contributor

@mzabaluev mzabaluev commented Nov 3, 2020

Motivation

#2882 removed the poll_write_buf method in AsyncWrite that could be implemented as a vectored write.
There is still a desire to use vectored I/O facilities on objects that support them efficiently, especially on the writing side.

Solution

Introduce a new trait, AsyncVectoredWrite, providing the poll_write_vectored method.
In contrast to the earlier poll_write_buf, the method is object-safe.

AsyncVectoredWrite is implemented for:

  • Sink;
  • TcpStream, UnixStream, their write halves;
  • standard in-memory containers;
  • generic pointer types that deref to an AsyncVectoredWrite types;
  • io::WriteHalf of an AsyncVectoredWrite object;
  • BufWriter, as well as write-through delegations on BufStream and BufReader.

The latter implementation allows using BufWriter and friends as buffering adapters in cases when generic code requires AsyncVectoredWrite.

The AsyncVectoredWriteExt utility trait provides the async-friendly method write_vectored for all types implementing AsyncVectoredWrite.

@Darksonn Darksonn added A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-net Module: tokio/net labels Nov 3, 2020
Reintroduce vectored I/O facilities in the new module io::vec,
starting from the poll_write_vectored method in the new
AsyncVectoredWrite trait.

Implement AsyncVectoredWrite for TcpStream.
io::Sink can consume vectored buffers just as well as it can do
single buffers.
An extension trait providing async-friendly methods for
all implementors of AsyncVectoredWrite.
Delegate these implementations to std::io::Write::write_vectored,
no blocking when writing to byte containers in memory.
Fill the buffer more eagerly over consecutive calls
to poll_write_vectored. At the first non-empty slice, the
buffer is flushed if the slice does not fit completely,
after which filling can continue until capacity is exhausted, or
there is an oversized slice for direct writing,
or there are no more slices to write.
@hawkw
Copy link
Member

hawkw commented Nov 20, 2020

I believe this is obviated by #3149, which also adds an API for vectored writes.

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-net Module: tokio/net
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants