Skip to content

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

Closed
@APTy

Description

@APTy

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    B-unstableBlocker: Implemented in the nightly compiler and unstable.T-libs-apiRelevant 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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions