chore: decrease direct depend on the sing package

This commit is contained in:
wwqgtxx
2023-01-16 10:50:31 +08:00
parent 643fdd0bce
commit 50832aab47
10 changed files with 108 additions and 73 deletions

View File

@ -4,23 +4,21 @@ import (
"bufio"
"net"
"github.com/sagernet/sing/common/buf"
sing_bufio "github.com/sagernet/sing/common/bufio"
"github.com/sagernet/sing/common/network"
"github.com/Dreamacro/clash/common/buf"
)
var _ network.ExtendedConn = (*BufferedConn)(nil)
var _ ExtendedConn = (*BufferedConn)(nil)
type BufferedConn struct {
r *bufio.Reader
network.ExtendedConn
ExtendedConn
}
func NewBufferedConn(c net.Conn) *BufferedConn {
if bc, ok := c.(*BufferedConn); ok {
return bc
}
return &BufferedConn{bufio.NewReader(c), sing_bufio.NewExtendedConn(c)}
return &BufferedConn{bufio.NewReader(c), NewExtendedConn(c)}
}
// Reader returns the internal bufio.Reader.
@ -58,7 +56,7 @@ func (c *BufferedConn) ReadBuffer(buffer *buf.Buffer) (err error) {
}
func (c *BufferedConn) Upstream() any {
if wrapper, ok := c.ExtendedConn.(*sing_bufio.ExtendedConnWrapper); ok {
if wrapper, ok := c.ExtendedConn.(*ExtendedConnWrapper); ok {
return wrapper.Conn
}
return c.ExtendedConn