-
Notifications
You must be signed in to change notification settings - Fork 13.7k
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.