github.com/igoogolx/clash@v1.19.8/common/net/bufconn.go (about) 1 package net 2 3 import ( 4 "bufio" 5 "net" 6 ) 7 8 type BufferedConn struct { 9 r *bufio.Reader 10 net.Conn 11 } 12 13 func NewBufferedConn(c net.Conn) *BufferedConn { 14 if bc, ok := c.(*BufferedConn); ok { 15 return bc 16 } 17 return &BufferedConn{bufio.NewReader(c), c} 18 } 19 20 // Reader returns the internal bufio.Reader. 21 func (c *BufferedConn) Reader() *bufio.Reader { 22 return c.r 23 } 24 25 // Peek returns the next n bytes without advancing the reader. 26 func (c *BufferedConn) Peek(n int) ([]byte, error) { 27 return c.r.Peek(n) 28 } 29 30 func (c *BufferedConn) Read(p []byte) (int, error) { 31 return c.r.Read(p) 32 } 33 34 func (c *BufferedConn) ReadByte() (byte, error) { 35 return c.r.ReadByte() 36 } 37 38 func (c *BufferedConn) UnreadByte() error { 39 return c.r.UnreadByte() 40 } 41 42 func (c *BufferedConn) Buffered() int { 43 return c.r.Buffered() 44 }