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

feat(s2n-quic-core): add buffer reader/writer traits #2097

Merged
merged 8 commits into from
Feb 8, 2024

Conversation

camshaft
Copy link
Contributor

@camshaft camshaft commented Jan 17, 2024

Description of changes:

This PR implements a number of buffer traits that makes it easy to support reading/writing streams of bytes while avoiding copies as much as possible.

Call-outs:

I've renamed the ReceiveBuffer to Reassembler, since it better describes what it's intended use is.

Testing:

Each of the concrete implementations should have a few tests showing them working and behaving correctly.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@camshaft camshaft force-pushed the camshaft/buffer-reader branch 5 times, most recently from c009209 to d33dfa2 Compare January 18, 2024 18:59
@camshaft camshaft changed the title feat(s2n-quic-core): add buffer reader feat(s2n-quic-core): add buffer reader/writer traits Jan 18, 2024
@camshaft camshaft force-pushed the camshaft/buffer-reader branch 8 times, most recently from e588bf2 to 4f2cbc2 Compare January 24, 2024 19:38
@camshaft camshaft force-pushed the camshaft/buffer-reader branch 2 times, most recently from bdfc68d to 8fcf0e5 Compare February 5, 2024 22:57
Copy link
Collaborator

@Mark-Simulacrum Mark-Simulacrum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got through quic/s2n-quic-core/src/buffer/reader/storage.rs for now, publishing the initial round of comments...

@camshaft camshaft force-pushed the camshaft/buffer-reader branch 2 times, most recently from 10ebab1 to d62c051 Compare February 6, 2024 21:17
@camshaft camshaft marked this pull request as ready for review February 6, 2024 23:42
@camshaft camshaft force-pushed the camshaft/buffer-reader branch 2 times, most recently from 3680946 to 0f61e93 Compare February 7, 2024 20:18
/// A wrapper around an underlying buffer (`duplex`) which will prefer to read/write from a
/// user-provided temporary buffer (`storage`). The underlying buffer (`duplex`)'s current
/// position and total length are updated if needed.
pub struct Interposer<'a, S, D>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where did this name come from? :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +22 to +24
/// Maps from an infallible error into a more specific error
#[inline]
pub fn mapped<E>(error: Error) -> Error<E> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this doing? Doesn't seem to change the error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is when you call a function that returns an Error<Infallible> in a function that returns Error<T>. The conversion is sound since the reader error can never fail, but we still need to translate the other two enum variants.

Empty::new(self)
}

/// Enables checking the reader for correctness invariants
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment could mention debug_assertions must be enabled to enable this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call

Comment on lines +63 to +64
// TODO add better support for copy avoidance by iterating to the appropriate slot and
// copying into that, if possible
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

want to add a tracking issue for these TODOs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was going to try and address it relatively quickly, since this current implementation doesn't really offer any copy avoidance. but i didn't want to group this optimization in this pr, since it's already very large and this change would also be quite large 😄

@camshaft camshaft force-pushed the camshaft/buffer-reader branch from 476e4da to 66cd9c9 Compare February 8, 2024 21:00
@camshaft camshaft merged commit 03f97ad into main Feb 8, 2024
117 of 120 checks passed
@camshaft camshaft deleted the camshaft/buffer-reader branch February 8, 2024 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants