Skip to content

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

@MaxMahem

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsA-ioArea: `std::io`, `std::fs`, `std::net` and `std::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