mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2025-10-09 02:30:05 +08:00
cleanup
This commit is contained in:
@@ -51,16 +51,22 @@ func (h *tcpHandler) relay(localConn, remoteConn net.Conn) {
|
|||||||
|
|
||||||
// Up Link
|
// Up Link
|
||||||
go func() {
|
go func() {
|
||||||
io.Copy(remoteConn, localConn)
|
if _, err := io.Copy(remoteConn, localConn); err != nil {
|
||||||
tcpCloseRead(localConn)
|
closeOnce()
|
||||||
tcpCloseWrite(remoteConn)
|
} else {
|
||||||
|
tcpCloseRead(localConn)
|
||||||
|
tcpCloseWrite(remoteConn)
|
||||||
|
}
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Down Link
|
// Down Link
|
||||||
io.Copy(localConn, remoteConn)
|
if _, err := io.Copy(localConn, remoteConn); err != nil {
|
||||||
tcpCloseRead(remoteConn)
|
closeOnce()
|
||||||
tcpCloseWrite(localConn)
|
} else {
|
||||||
|
tcpCloseRead(remoteConn)
|
||||||
|
tcpCloseWrite(localConn)
|
||||||
|
}
|
||||||
|
|
||||||
wg.Wait() // Wait for Up Link done
|
wg.Wait() // Wait for Up Link done
|
||||||
|
|
||||||
|
@@ -3,8 +3,6 @@ package socks
|
|||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/xjasonlyu/tun2socks/common/log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type duplexConn interface {
|
type duplexConn interface {
|
||||||
@@ -15,14 +13,12 @@ type duplexConn interface {
|
|||||||
|
|
||||||
func tcpCloseRead(conn net.Conn) {
|
func tcpCloseRead(conn net.Conn) {
|
||||||
if c, ok := conn.(duplexConn); ok {
|
if c, ok := conn.(duplexConn); ok {
|
||||||
log.Warnf("ok!----")
|
|
||||||
c.CloseRead()
|
c.CloseRead()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func tcpCloseWrite(conn net.Conn) {
|
func tcpCloseWrite(conn net.Conn) {
|
||||||
if c, ok := conn.(duplexConn); ok {
|
if c, ok := conn.(duplexConn); ok {
|
||||||
log.Warnf("ok!++++")
|
|
||||||
c.CloseWrite()
|
c.CloseWrite()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user