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

Use BufferedRead when reading #56

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

rmja
Copy link
Member

@rmja rmja commented Oct 31, 2023

Currently when e.g. reading a chunked response body, we request a read() with a single byte buffer. This PR uses the BufferedRead as an intermediate to greatly avoid small connection reads when tls is not in use.

cc @bugadani

@rmja
Copy link
Member Author

rmja commented Oct 31, 2023

I can now see that the small reads are actually not happening, so maybe the motivation to include this is not as strong as I first thought.

src/reader.rs Outdated
// The matches/if let dance is to fix lifetime of the borrowed inner connection.
#[cfg(feature = "embedded-tls")]
if matches!(self.buffered.bypass(), Ok(HttpConnection::Tls(_))) {
if let HttpConnection::Tls(ref mut tls) = self.buffered.bypass().unwrap() {
Copy link
Contributor

Choose a reason for hiding this comment

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

bypass is a neat idea!

So do I understand correctly that if let Ok(HttpConnection::Tls(ref mut tls)) = self.buffered.bypass() { without the outer matches! would not work˙, even if you wrap the whole block in a new scope?

Copy link
Member Author

Choose a reason for hiding this comment

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

Year, I have tried multiple versions, which all fail to compile. The problem is that self.buffered is still borrowed in the else branch, and I cannot figure out how to avoid that. Any good proposals?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to change .bypass() to return Result<&mut T, &mut Self>?

Copy link
Member Author

Choose a reason for hiding this comment

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

If you think that would make it work, then yes:)

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess I can try locally first :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, no, it can't because we still need to handle the HttpConnection::Plain branch :(

@bugadani
Copy link
Contributor

Yeah the network stack won't receive bytes one by one but this is certainly a cleaner implementation than what we had before. Minus the matches! hack, which looks just weird, I hope we can drop that somehow.

src/reader.rs Outdated Show resolved Hide resolved
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.

None yet

2 participants