chore: make all net.Conn wrapper can pass through N.ExtendedConn

This commit is contained in:
wwqgtxx
2023-04-02 22:24:46 +08:00
parent 2ff0f94262
commit 99f84b8a66
10 changed files with 45 additions and 65 deletions

View File

@ -4,10 +4,12 @@ import (
"net"
"runtime"
"time"
"github.com/Dreamacro/clash/common/buf"
)
type refConn struct {
conn net.Conn
conn ExtendedConn
ref any
}
@ -55,8 +57,20 @@ func (c *refConn) Upstream() any {
return c.conn
}
func (c *refConn) ReadBuffer(buffer *buf.Buffer) error {
defer runtime.KeepAlive(c.ref)
return c.conn.ReadBuffer(buffer)
}
func (c *refConn) WriteBuffer(buffer *buf.Buffer) error {
defer runtime.KeepAlive(c.ref)
return c.conn.WriteBuffer(buffer)
}
var _ ExtendedConn = (*refConn)(nil)
func NewRefConn(conn net.Conn, ref any) net.Conn {
return &refConn{conn: conn, ref: ref}
return &refConn{conn: NewExtendedConn(conn), ref: ref}
}
type refPacketConn struct {