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

net: Add ReadHalf::{peek,poll_peak} #2151

Merged

Conversation

kleimkuhler
Copy link
Contributor

@kleimkuhler kleimkuhler commented Jan 22, 2020

Motivation

Closes #2136

Solution

The &mut self requirements for TcpStream methods ensure that there are at
most two tasks using the stream--one for reading and one for writing.

TcpStream::split allows two separate tasks to hold a reference to a single
TcpStream. TcpStream::{peek,poll_peek} only poll for read readiness, and
therefore are safe to use with a ReadHalf.

Instead of duplicating TcpStream::poll_peek, a private method is now used by
both poll_peek methods that uses the fact that only a &TcpStream is
required.

Signed-off-by: Kevin Leimkuhler kevin@kleimkuhler.com

Signed-off-by: Kevin Leimkuhler <kevin@kleimkuhler.com>
@kleimkuhler kleimkuhler requested a review from a team January 22, 2020 17:07
@carllerche carllerche merged commit 7f58007 into tokio-rs:master Jan 22, 2020
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.

TcpStream's ReadHalf is not peekable
3 participants