add utils.go to socks

This commit is contained in:
Jason
2019-08-11 21:03:41 +08:00
parent 2c086ff101
commit d571cbef78
2 changed files with 31 additions and 15 deletions

View File

@@ -42,6 +42,9 @@ func (h *tcpHandler) relay(localConn, remoteConn net.Conn) {
})
}
// Close
defer closeOnce()
// WaitGroup
var wg sync.WaitGroup
wg.Add(1)
@@ -56,7 +59,6 @@ func (h *tcpHandler) relay(localConn, remoteConn net.Conn) {
// Down Link
io.Copy(localConn, remoteConn)
tcpCloseRead(localConn)
defer closeOnce()
wg.Wait() // Wait for Up Link done
@@ -120,17 +122,3 @@ func (h *tcpHandler) Handle(localConn net.Conn, target *net.TCPAddr) error {
log.Access(process, "proxy", target.Network(), localConn.LocalAddr().String(), targetAddr)
return nil
}
func tcpKeepAlive(conn net.Conn) {
if tcp, ok := conn.(*net.TCPConn); ok {
tcp.SetKeepAlive(true)
tcp.SetKeepAlivePeriod(30 * time.Second)
}
}
func tcpCloseRead(conn net.Conn) {
if c, ok := conn.(interface{ CloseRead() error }); ok {
log.Warnf("ok!")
c.CloseRead()
}
}