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

28
proxy/socks/utils.go Normal file
View File

@@ -0,0 +1,28 @@
package socks
import (
"net"
"time"
"github.com/xjasonlyu/tun2socks/common/log"
)
type duplexConn interface {
net.Conn
CloseRead() error
CloseWrite() error
}
func tcpCloseRead(conn net.Conn) {
if c, ok := conn.(duplexConn); ok {
log.Warnf("ok!----")
c.CloseRead()
}
}
func tcpKeepAlive(conn net.Conn) {
if tcp, ok := conn.(*net.TCPConn); ok {
tcp.SetKeepAlive(true)
tcp.SetKeepAlivePeriod(30 * time.Second)
}
}