mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2025-10-29 03:02:30 +08:00
Update tcp.go
This commit is contained in:
@@ -45,29 +45,30 @@ func (h *tcpHandler) relay(localConn, remoteConn net.Conn) {
|
|||||||
// Close
|
// Close
|
||||||
defer closeOnce()
|
defer closeOnce()
|
||||||
|
|
||||||
upCh := make(chan struct{})
|
up := make(chan struct{})
|
||||||
|
down := make(chan struct{})
|
||||||
|
|
||||||
// UpLink
|
// UpLink
|
||||||
go func() {
|
go func() {
|
||||||
if _, err := io.Copy(remoteConn, localConn); err != nil {
|
if _, err := io.Copy(remoteConn, localConn); err != nil {
|
||||||
closeOnce()
|
closeOnce()
|
||||||
}
|
}
|
||||||
upCh <- struct{}{}
|
up <- struct{}{}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// DownLink
|
// DownLink
|
||||||
if _, err := io.Copy(localConn, remoteConn); err != nil {
|
go func() {
|
||||||
closeOnce()
|
if _, err := io.Copy(localConn, remoteConn); err != nil {
|
||||||
}
|
closeOnce()
|
||||||
|
}
|
||||||
|
down <- struct{}{}
|
||||||
|
}()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-upCh:
|
case <-up: // Wait for UpLink done.
|
||||||
case <-time.After(10 * time.Second):
|
case <-down:
|
||||||
closeOnce()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//<-upCh // Wait for UpLink done.
|
|
||||||
|
|
||||||
if h.sessionStater != nil {
|
if h.sessionStater != nil {
|
||||||
h.sessionStater.RemoveSession(localConn)
|
h.sessionStater.RemoveSession(localConn)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user