Skip to content
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

Get length of packet from datagram sockets (UdpSocket, UnixDatagram) #100248

Open
nnishant776 opened this issue Aug 7, 2022 · 0 comments
Open
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.

Comments

@nnishant776
Copy link

Summary

Provide an API to peek/get the length of the datagram

The unstable feature unix_socket_peek adds methods peek and peek_from for UnixDatagram and UnixStream. 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 to peek, MSG_TRUNC ored with the MSG_PEEK flag can be passed to the recv call, which would only peek 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.

@Mark-Simulacrum Mark-Simulacrum added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. C-feature-request Category: A feature request, i.e: not implemented / a PR. labels Aug 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.
Projects
None yet
Development

No branches or pull requests

2 participants