2
0
mirror of https://github.com/soheilhy/cmux.git synced 2024-11-09 19:21:52 +08:00

Reset the sniffing buffer when not needed

The sniffing buffer will live as long as the connection is open,
and we should reset it as soon as the application has read all the
sniffed data.
This commit is contained in:
Soheil Hassas Yeganeh 2016-09-25 11:40:41 -04:00
parent 3ac8d3a667
commit f661dcfb59

View File

@ -42,6 +42,10 @@ func (s *bufferedReader) Read(p []byte) (int, error) {
bn := copy(p, s.buffer.Bytes()[s.bufferRead:s.bufferSize])
s.bufferRead += bn
return bn, s.lastErr
} else if !s.sniffing && s.buffer.Cap() != 0 {
// We don't need the buffer anymore.
// Reset it to release the internal slice.
s.buffer = bytes.Buffer{}
}
// If there is nothing more to return in the sniffed buffer, read from the