chore: drop bufio.Reader in BufferedConn to let gc can clean up its internal buf
This commit is contained in:
parent
4f49b9ec9c
commit
6e539f4b0d
1 changed files with 4 additions and 3 deletions
|
@ -62,7 +62,7 @@ func (c *BufferedConn) Buffered() int {
|
|||
}
|
||||
|
||||
func (c *BufferedConn) ReadBuffer(buffer *buf.Buffer) (err error) {
|
||||
if c.r.Buffered() > 0 {
|
||||
if c.r != nil && c.r.Buffered() > 0 {
|
||||
_, err = buffer.ReadOnceFrom(c.r)
|
||||
return
|
||||
}
|
||||
|
@ -70,10 +70,11 @@ func (c *BufferedConn) ReadBuffer(buffer *buf.Buffer) (err error) {
|
|||
}
|
||||
|
||||
func (c *BufferedConn) ReadCached() *buf.Buffer { // call in sing/common/bufio.Copy
|
||||
if c.r.Buffered() > 0 {
|
||||
if c.r != nil && c.r.Buffered() > 0 {
|
||||
length := c.r.Buffered()
|
||||
b, _ := c.r.Peek(length)
|
||||
_, _ = c.r.Discard(length)
|
||||
c.r = nil // drop bufio.Reader to let gc can clean up its internal buf
|
||||
return buf.As(b)
|
||||
}
|
||||
return nil
|
||||
|
@ -84,7 +85,7 @@ func (c *BufferedConn) Upstream() any {
|
|||
}
|
||||
|
||||
func (c *BufferedConn) ReaderReplaceable() bool {
|
||||
if c.r.Buffered() > 0 {
|
||||
if c.r != nil && c.r.Buffered() > 0 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
|
Loading…
Reference in a new issue