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.
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.