Skip to content

v0.2.11: Avoiding UDP truncated reads.

Compare
Choose a tag to compare
@puellanivis puellanivis released this 08 May 12:33
· 64 commits to master since this release
01e1625

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 with io.LimitReader)
  • files.Copy now uses a fuzzyLimitedReader that does not narrow the Read 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.