Get length of packet from datagram sockets (UdpSocket
, UnixDatagram
)
#100248
Labels
C-feature-request
Category: A feature request, i.e: not implemented / a PR.
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
Summary
Provide an API to peek/get the length of the datagram
The unstable feature
unix_socket_peek
adds methodspeek
andpeek_from
forUnixDatagram
andUnixStream
. While they allow to peek at the the data, however, the API returns the number of bytes read on success. To get the length of the datagram instead of the bytes read, in an API similar topeek
,MSG_TRUNC
or
ed with theMSG_PEEK
flag can be passed to therecv
call, which would onlypeek
at the data but return the length the next datagram on success.Motivation
This can be helpful in use cases for memory usage optimization where we can allocate buffers dynamically with just enough size for reading the data packet. This is helpful when the connections or message are infrequent, for example, an application configuration message.
The text was updated successfully, but these errors were encountered: