pool: added bufio.Reader pool

This commit is contained in:
nadoo committed 2020-11-03 22:52:50 +08:00
1 parent c15c55fe05
commit 417ac556f7
29 files changed
+188 -168

No files matched your search

+6 -1
View File
@@ -32,7 +32,7 @@ func NewConn(c net.Conn) *Conn {
if conn, ok := c.(*Conn); ok {
return conn
}
return &Conn{bufio.NewReader(c), c}
return &Conn{pool.GetBufReader(c), c}
}
// Reader returns the internal bufio.Reader.
@@ -73,6 +73,11 @@ func Relay(left, right net.Conn) error {
return nil
}
func (c *Conn) Close() error {
pool.PutBufReader(c.r)
return c.Conn.Close()
}
// Copy copies from src to dst.
func Copy(dst io.Writer, src io.Reader) (written int64, err error) {
dst = underlyingWriter(dst)