v0.2.11: Avoiding UDP truncated reads.
Using files.Copy
with a UDP source had a problem where it was sometimes making reads with small buffers, which could lead to truncation of packets. This was solved in two parts:
- Datagram readers are now a buffered stream fed from individual packet reads. This means all
files.Reader
can be assumed to operate compatibly as a stream. (i.e. it will not break if used withio.LimitReader
) files.Copy
now uses afuzzyLimitedReader
that does not narrow theRead
buffer to ensure only at most N bytes are read from its underlying source.
As a result of the datagram readers now being buffered, they now also have a receiver method of ReadPacket(buf []byte) (n int, err error)
which does not ever buffer its reads, so that it can be type-asserted by packet-aware code to avoid potentially going through the buffer.