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) {
|
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)
|
_, err = buffer.ReadOnceFrom(c.r)
|
||||||
return
|
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
|
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()
|
length := c.r.Buffered()
|
||||||
b, _ := c.r.Peek(length)
|
b, _ := c.r.Peek(length)
|
||||||
_, _ = c.r.Discard(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 buf.As(b)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -84,7 +85,7 @@ func (c *BufferedConn) Upstream() any {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *BufferedConn) ReaderReplaceable() bool {
|
func (c *BufferedConn) ReaderReplaceable() bool {
|
||||||
if c.r.Buffered() > 0 {
|
if c.r != nil && c.r.Buffered() > 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|
Loading…
Reference in a new issue