Repository navigation
Implement BufRead for Reader, Stream, and StreamOwned - #2303
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2303 +/- ##
=======================================
Coverage 94.82% 94.83%
=======================================
Files 104 104
Lines 24100 24150 +50
=======================================
+ Hits 22853 22902 +49
- Misses 1247 1248 +1 ☔ View full report in Codecov by Sentry. |
|
I'll let @ctz have a look at this first. |
There was a problem hiding this comment.
I think this looks fairly reasonable? Naturally it needs tests.
Mostly unrelated: I've also considered adding a pub fn take_chunk(&mut self) -> io::Result<Option<Vec<u8>>> to Reader, to allow move-style buffered IO (rather than the copy-style IO implied by all the std::io traits.) I don't think that helps or hinders with this addition though.
If this is motivated by a downstream need in tokio-rustls it would also be nice to see a draft implementing that side before this is merged. |
|
Here is the downstream PR: rustls/tokio-rustls#100 I will add tests. |
|
I added a number of tests for BufRead behaviour and cleaned up the code a bit too. I've extended the PR to implement BufRead for Stream/StreamOwned as it seemed logical and some tests that I wanted to extend were relying on it. |
|
This also provides a foundation to easily resolve rustls/tokio-rustls#55 (without rewriting the whole thing to use the unbuffered API): rustls/tokio-rustls@655c396?w=1 |
c6e7ce8 to
6f1ddc8
Compare
|
I've cleaned up the commit history. I didn't realize this project preserves commits from PRs when merging - my mistake for not reading CONTRIBUTING.md carefully. |
djc
left a comment
There was a problem hiding this comment.
Nice, this now has a pretty clean commit history. Some minor questions left.
|
|
||
| impl BufRead for Reader<'_> { | ||
| /// Obtain a chunk of plaintext data received from the peer over this TLS connection. | ||
| /// This reads the same data as [`Reader::read`], but returns a reference instead of |
There was a problem hiding this comment.
Nit: please refer to functions and methods with trailing () in order to distinguish from fields.
Benchmark resultsInstruction countsSignificant differencesThere are no significant instruction count differences Other differencesClick to expand
Wall-timeSignificant differencesClick to expand
Other differencesClick to expand
Additional informationCheckout details:
|
|
I'm not sure if I should be worried about the benchmark results - it looks like it could just be random variation? I don't really see how this change could lead to a regression but only in two random handshake tests |
cpu
left a comment
There was a problem hiding this comment.
Thanks! This is nice and tidy ✨
I'm not sure if I should be worried about the benchmark results - it looks like it could just be random variation?
I think it's safe to ignore here.
This is basically a reroll of #870 against the latest version of the code.
New in this PR is an alternate method
Reader::into_first_chunk(other naming suggestions welcome) that acts likefill_bufbut returns a slice with a longer lifetime, at the cost of consumingself(needed in order to steal the&mut ConnectionCommonborrow). This makes it possible to implement AsyncBufRead in tokio_rustls without necessarily implementing BufRead directly on ConnectionCommon. It's also needed to implement BufRead for StreamOwned.