Have encapsulation.ReadData read into a provided buffer.

Instead of unconditionally allocating its own.
This commit is contained in:
David Fifield 2023-06-26 02:12:46 +00:00
parent 648609dbea
commit 001f691b47
4 changed files with 122 additions and 58 deletions

View file

@ -37,11 +37,11 @@ func newEncapsulationPacketConn(
// ReadFrom reads an encapsulated packet from the stream.
func (c *encapsulationPacketConn) ReadFrom(p []byte) (int, net.Addr, error) {
data, err := encapsulation.ReadData(c.ReadWriteCloser)
n, err := encapsulation.ReadData(c.ReadWriteCloser, p)
if err != nil {
return 0, c.remoteAddr, err
return n, c.remoteAddr, err
}
return copy(p, data), c.remoteAddr, nil
return n, c.remoteAddr, nil
}
// WriteTo writes an encapsulated packet to the stream.