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

Fix AsyncRead impl for TcpStream #107

Merged
merged 3 commits into from
Mar 16, 2023
Merged

Fix AsyncRead impl for TcpStream #107

merged 3 commits into from
Mar 16, 2023

Conversation

mcches
Copy link
Contributor

@mcches mcches commented Mar 16, 2023

Buffer the remainder of a received data segment to serve subsequent
reads.

Buffer the remainder of a received data segment to serve subsequent
reads.
@mcches mcches linked an issue Mar 16, 2023 that may be closed by this pull request
@mcches mcches requested a review from camshaft March 16, 2023 21:26
Copy link
Member

@carllerche carllerche left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines 178 to 186
let (a, b) = avail.split_at(amt);

buf.put_slice(a);

if b.is_empty() {
None
} else {
Some(Bytes::copy_from_slice(b))
}
Copy link
Collaborator

@camshaft camshaft Mar 16, 2023

Choose a reason for hiding this comment

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

Better to use advance so you don't have to copy the bytes out:

Suggested change
let (a, b) = avail.split_at(amt);
buf.put_slice(a);
if b.is_empty() {
None
} else {
Some(Bytes::copy_from_slice(b))
}
buf.put_slice(&avail[..amt]);
avail.advance(amt);
if avail.is_empty() {
None
} else {
Some(avail)
}

@mcches mcches merged commit 0accb6a into main Mar 16, 2023
@mcches mcches deleted the async-read branch March 16, 2023 21:49
@mcches mcches mentioned this pull request Mar 30, 2023
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.

Fix AsyncRead impl for TcpStream
3 participants