-
-
Notifications
You must be signed in to change notification settings - Fork 15k
Provide "peek" APIs to std::net sockets #38980
Copy link
Copy link
Closed
Labels
B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.In the final comment period and will be merged soon unless new substantive objections are raised.
Metadata
Metadata
Assignees
Labels
B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.In the final comment period and will be merged soon unless new substantive objections are raised.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Summary
Provide "peek" APIs to
std::netsockets, 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_PEEKto 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.