chore: decrease goroutine used in core tunnel

This commit is contained in:
wwqgtxx
2023-09-28 18:59:31 +08:00
parent 21fb5f75b8
commit e0458a8fde
42 changed files with 252 additions and 269 deletions

View File

@ -8,19 +8,19 @@ import (
C "github.com/Dreamacro/clash/constant"
)
var tcpIn chan<- C.ConnContext
var tunnel C.Tunnel
func New(in chan<- C.ConnContext) {
tcpIn = in
func New(t C.Tunnel) {
tunnel = t
}
func HandleTcp(address string) (conn net.Conn, err error) {
if tcpIn == nil {
if tunnel == nil {
return nil, errors.New("tcp uninitialized")
}
// executor Parsed
conn1, conn2 := net.Pipe()
context := inbound.NewInner(conn2, address)
tcpIn <- context
go tunnel.HandleTCPConn(context)
return conn1, nil
}