-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Comments
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? |
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 :) |
Cool, I give that a go! |
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? |
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! |
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
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
Reopening as the tracking issue for this feature |
@rfcbot fcp merge This is a pretty straightforward binding to the underlying system APIs. |
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. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period is now complete. |
Closes rust-lang#38863 Closes rust-lang#38980 Closes rust-lang#38903 Closes rust-lang#36648
Stabilize library features for 1.18.0 Closes #38863 Closes #38980 Closes #38903 Closes #36648 r? @alexcrichton @rust-lang/libs
Closes rust-lang#38863 Closes rust-lang#38980 Closes rust-lang#38903 Closes rust-lang#36648
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 flagMSG_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.The text was updated successfully, but these errors were encountered: