UcpSocket::send_to indicates possible partial write behavior inaccurately.
@xizheyin is already working on this.
Since Aug 28, 2025.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
The current documentation for UdpSocket::send_to is misleading about the possibility of partial writes when passed large buffers. Specifically, the docs state in part:
Sends data on the socket to the given address. On success, returns the number of bytes written. Note that the operating system may refuse buffers larger than 65507. However, partial writes are not possible until buffer sizes above i32::MAX.
This seems inaccurate. UDP max (disregarding jumbo frames, which I do not believe are in play here) is 65,507, as noted, as defined by the protocol, which has only a 16-byte field for length. In practice, the maximum practical size is often much smaller. The documentation, though, indicates that a partial write could be possible for buffer sizes above i32::MAX (perhaps based on the clamp that happens internally). This is misleading, as i32::MAX is greatly above the aforementioned UDP max; any attempt to send more should fail with EMSGSIZE regardless of the passed length.
In addition, even if this sort of partial write was done, it would be inappropriate for UDP, which is expected to be an all-or-nothing protocol.
The inaccurate statement should simply be removed. Additionally, the code might consider checking to see if buffer length exceeds the 16-byte limit, and erroring early as a small optimization, during the clamping of buffer length.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.