-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
mzabaluev
force-pushed
the
vectored-write
branch
from
November 7, 2020 20:00
a0425e7
to
a553a7b
Compare
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.
mzabaluev
force-pushed
the
vectored-write
branch
from
November 8, 2020 00:00
a553a7b
to
ba29993
Compare
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
#2882 removed the
poll_write_buf
method inAsyncWrite
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 thepoll_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;AsyncVectoredWrite
types;io::WriteHalf
of anAsyncVectoredWrite
object;BufWriter
, as well as write-through delegations onBufStream
andBufReader
.The latter implementation allows using
BufWriter
and friends as buffering adapters in cases when generic code requiresAsyncVectoredWrite
.The
AsyncVectoredWriteExt
utility trait provides the async-friendly methodwrite_vectored
for all types implementingAsyncVectoredWrite
.