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
util: add writev-aware poll_write_buf
#3156
Conversation
Looks like |
Probably something was fixed in Rust 1.48 stable. (It looks like modules that were not previously formatted correctly are now formatted.) EDIT: filed #3158 |
This commit adds `poll_write_buf` and `write_buf` functions to `tokio_util::io`, analogous to the existing `poll_read_buf` and `read_buf` functions. These functions write from a `Buf` to an `AsyncWrite`, advancing the `Buf`'s internal cursor. In addition, when the `AsyncWrite` supports vectored writes (i.e. its `is_write_vectored` method returns `true`), they will use vectored IO. I copied the documentation for these functions from the docs from Tokio 0.2's `AsyncWrite::poll_write_buf` and `AsyncWriteExt::write_buf` functions, with some minor modifications as appropriate.
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
4804fba
to
a124b06
Compare
Note that there still is a provided implementation of I think an extension method is more convenient than the free-standing function, while the object safety concerns that led to the removal of |
The |
Per a Discord conversation, I'm going to downscope this PR to just add |
Instead, we'll add vectored write support to `tokio`'s `AsyncWriteExt::write_buf` method. This PR only adds `poll_write_buf` in `tokio-util`. Signed-off-by: Eliza Weisman <eliza@buoyant.io>
poll_write_buf
and write_buf
poll_write_buf
@carllerche and @Darksonn, I've updated this PR to just add This should be ready for a review. It would be nice to publish |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems ok to me.
Motivation
In Tokio 0.2,
AsyncRead
andAsyncWrite
hadpoll_write_buf
andpoll_read_buf
methods for reading and writing to implementers ofbytes
Buf
andBufMut
traits. In 0.3, these were removed, butpoll_read_buf
was added as a free function intokio-util
. However,there is currently no
poll_write_buf
.Now that
AsyncWrite
has regained support for vectored writes in #3149,there's a lot of potential benefit in having a
poll_write_buf
thatuses vectored writes when supported and non-vectored writes when not
supported, so that users don't have to reimplement this.
Solution
This PR adds a
poll_write_buf
function totokio_util::io
, analogousto the existing
poll_read_buf
function.This function writes from a
Buf
to anAsyncWrite
, advancing theBuf
's internal cursor. In addition, when theAsyncWrite
supportsvectored writes (i.e. its
is_write_vectored
method returnstrue
),it will use vectored IO.
I copied the documentation for this functions from the docs from Tokio
0.2's
AsyncWrite::poll_write_buf
, with some minor modifications asappropriate.
Finally, I fixed a minor issue in the existing docs for
poll_read_buf
and
read_buf
, and updatedtokio_util::codec
to usepoll_write_buf
.Signed-off-by: Eliza Weisman eliza@buoyant.io