Skip to content

UcpSocket::send_to indicates possible partial write behavior inaccurately. #145862

Open

Description

@MaxMahem

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.

Activity

  1. transferred this issue fromrust-lang/referenceon Aug 25, 2025
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Aug 25, 2025
  3. added
    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    A-ioArea: `std::io` (note: `std::fs`, `std::net`, `std::path` are A-filesystem, A-net, A-path)
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Aug 26, 2025
  4. self-assigned this
    on Aug 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsA-ioArea: `std::io` (note: `std::fs`, `std::net`, `std::path` are A-filesystem, A-net, A-path)T-libsRelevant to the library team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions