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

Provide "peek" APIs to std::net sockets #38980

Closed
APTy opened this issue Jan 11, 2017 · 10 comments
Closed

Provide "peek" APIs to std::net sockets #38980

APTy opened this issue Jan 11, 2017 · 10 comments
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@APTy
Copy link
Contributor

APTy commented Jan 11, 2017

Summary

Provide "peek" APIs to std::net sockets, for example:

  • UdpSocket.peek()
  • UdpSocket.peek_from()
  • TcpStream.peek()

These methods enable socket reads without side-effects. That is, repeated calls to peek() return identical data. This can be accomplished by providing the POSIX flag MSG_PEEK to the underlying socket read operations.

Motivation

This is valuable in cases where a user wishes to validate if new data exists in the socket, without consuming that data completely. For example, a user may wish to use peek() as a method of polling the socket to find out if new messages are available (or to determine the amount of data available), before deferring to another function to do the actual work of reading and parsing the socket's data.

@cseale
Copy link
Contributor

cseale commented Jan 11, 2017

This sounds like a good candidate for a first PR, would you think? If so I would like to take this on, with maybe a bit of help?

@APTy
Copy link
Contributor Author

APTy commented Jan 11, 2017

Thanks for offering! I am planning to submit a PR for a part 1 (UdpSocket implementation), and needed an issue to reference for the feature flag. Feel free to tackle TcpStream in parallel :)

@cseale
Copy link
Contributor

cseale commented Jan 11, 2017

Cool, I give that a go!

@cseale
Copy link
Contributor

cseale commented Jan 11, 2017

Looking at your branch, it might be an aggressive commit for me for my first contribution, unless perhaps you could provide me with a bit of detail on your intended implementation or somewhere maybe I could go for reference?

@APTy
Copy link
Contributor Author

APTy commented Jan 13, 2017

That's okay, I went ahead and added the TcpStream implementation, since it was pretty closely related to the Socket updates I was making. Thanks anyway!

frewsxcv added a commit to frewsxcv/rust that referenced this issue Feb 5, 2017
Add peek APIs to std::net

Adds "peek" APIs to `std::net` sockets, including:
- `UdpSocket.peek()`
- `UdpSocket.peek_from()`
- `TcpStream.peek()`

These methods enable socket reads without side-effects. That is, repeated calls to `peek()` return identical data. This is accomplished by providing the POSIX flag `MSG_PEEK` to the underlying socket read operations.

This also moves the current implementation of `recv_from` out of the platform-independent `sys_common` and into respective `sys/windows` and `sys/unix` implementations. This allows for more platform-dependent implementations where necessary.

Fixes rust-lang#38980
frewsxcv added a commit to frewsxcv/rust that referenced this issue Feb 5, 2017
Add peek APIs to std::net

Adds "peek" APIs to `std::net` sockets, including:
- `UdpSocket.peek()`
- `UdpSocket.peek_from()`
- `TcpStream.peek()`

These methods enable socket reads without side-effects. That is, repeated calls to `peek()` return identical data. This is accomplished by providing the POSIX flag `MSG_PEEK` to the underlying socket read operations.

This also moves the current implementation of `recv_from` out of the platform-independent `sys_common` and into respective `sys/windows` and `sys/unix` implementations. This allows for more platform-dependent implementations where necessary.

Fixes rust-lang#38980
@alexcrichton
Copy link
Member

Reopening as the tracking issue for this feature

@alexcrichton alexcrichton reopened this Feb 8, 2017
@alexcrichton alexcrichton added B-unstable Blocker: Implemented in the nightly compiler and unstable. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Feb 8, 2017
@sfackler
Copy link
Member

@rfcbot fcp merge

This is a pretty straightforward binding to the underlying system APIs.

@rfcbot
Copy link

rfcbot commented Mar 24, 2017

Team member @sfackler has proposed to merge this. The next step is review by the rest of the tagged teams:

No concerns currently listed.

Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot
Copy link

rfcbot commented Apr 11, 2017

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label Apr 11, 2017
@rfcbot
Copy link

rfcbot commented Apr 21, 2017

The final comment period is now complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants