mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2025-10-08 18:20:41 +08:00
32 lines
461 B
Go
32 lines
461 B
Go
package socks
|
|
|
|
import (
|
|
"net"
|
|
"time"
|
|
)
|
|
|
|
type duplexConn interface {
|
|
net.Conn
|
|
CloseRead() error
|
|
CloseWrite() error
|
|
}
|
|
|
|
func tcpCloseRead(conn net.Conn) {
|
|
if c, ok := conn.(duplexConn); ok {
|
|
c.CloseRead()
|
|
}
|
|
}
|
|
|
|
func tcpCloseWrite(conn net.Conn) {
|
|
if c, ok := conn.(duplexConn); ok {
|
|
c.CloseWrite()
|
|
}
|
|
}
|
|
|
|
func tcpKeepAlive(conn net.Conn) {
|
|
if tcp, ok := conn.(*net.TCPConn); ok {
|
|
tcp.SetKeepAlive(true)
|
|
tcp.SetKeepAlivePeriod(30 * time.Second)
|
|
}
|
|
}
|