Revert: cli tcp-wait-timeout option

This reverts commit 2c51a65685.
This commit is contained in:
xjasonlyu
2023-04-03 17:57:13 +08:00
parent ad522ebb35
commit 20499c6432
4 changed files with 7 additions and 15 deletions

View File

@@ -123,10 +123,6 @@ func general(k *Key) error {
log.Infof("[DIALER] set fwmark: %#x", k.Mark) log.Infof("[DIALER] set fwmark: %#x", k.Mark)
} }
if k.TCPWaitTimeout > 0 {
tunnel.SetTCPWaitTimeout(k.TCPWaitTimeout)
}
if k.UDPTimeout > 0 { if k.UDPTimeout > 0 {
if k.UDPTimeout < time.Second { if k.UDPTimeout < time.Second {
return errors.New("invalid udp timeout value") return errors.New("invalid udp timeout value")

View File

@@ -13,8 +13,7 @@ type Key struct {
TCPModerateReceiveBuffer bool `yaml:"tcp-moderate-receive-buffer"` TCPModerateReceiveBuffer bool `yaml:"tcp-moderate-receive-buffer"`
TCPSendBufferSize string `yaml:"tcp-send-buffer-size"` TCPSendBufferSize string `yaml:"tcp-send-buffer-size"`
TCPReceiveBufferSize string `yaml:"tcp-receive-buffer-size"` TCPReceiveBufferSize string `yaml:"tcp-receive-buffer-size"`
TCPWaitTimeout time.Duration `yaml:"tcp-wait-timeout"`
UDPTimeout time.Duration `yaml:"udp-timeout"`
TUNPreUp string `yaml:"tun-pre-up"` TUNPreUp string `yaml:"tun-pre-up"`
TUNPostUp string `yaml:"tun-post-up"` TUNPostUp string `yaml:"tun-post-up"`
UDPTimeout time.Duration `yaml:"udp-timeout"`
} }

View File

@@ -36,7 +36,6 @@ func init() {
flag.StringVar(&key.TCPSendBufferSize, "tcp-sndbuf", "", "Set TCP send buffer size for netstack") flag.StringVar(&key.TCPSendBufferSize, "tcp-sndbuf", "", "Set TCP send buffer size for netstack")
flag.StringVar(&key.TCPReceiveBufferSize, "tcp-rcvbuf", "", "Set TCP receive buffer size for netstack") flag.StringVar(&key.TCPReceiveBufferSize, "tcp-rcvbuf", "", "Set TCP receive buffer size for netstack")
flag.BoolVar(&key.TCPModerateReceiveBuffer, "tcp-auto-tuning", false, "Enable TCP receive buffer auto-tuning") flag.BoolVar(&key.TCPModerateReceiveBuffer, "tcp-auto-tuning", false, "Enable TCP receive buffer auto-tuning")
flag.DurationVar(&key.TCPWaitTimeout, "tcp-wait-timeout", 0, "Set timeout before closing each TCP connection")
flag.StringVar(&key.TUNPreUp, "tun-pre-up", "", "Execute a command before TUN device setup") flag.StringVar(&key.TUNPreUp, "tun-pre-up", "", "Execute a command before TUN device setup")
flag.StringVar(&key.TUNPostUp, "tun-post-up", "", "Execute a command after TUN device setup") flag.StringVar(&key.TUNPostUp, "tun-post-up", "", "Execute a command after TUN device setup")
flag.BoolVar(&versionFlag, "version", false, "Show version and then quit") flag.BoolVar(&versionFlag, "version", false, "Show version and then quit")

View File

@@ -15,12 +15,10 @@ import (
"github.com/xjasonlyu/tun2socks/v2/tunnel/statistic" "github.com/xjasonlyu/tun2socks/v2/tunnel/statistic"
) )
// _tcpWaitTimeout is the default timeout to wait after closing each TCP connection. const (
var _tcpWaitTimeout = 5 * time.Second // tcpWaitTimeout implements a TCP half-close timeout.
tcpWaitTimeout = 60 * time.Second
func SetTCPWaitTimeout(t time.Duration) { )
_tcpWaitTimeout = t
}
func handleTCPConn(originConn adapter.TCPConn) { func handleTCPConn(originConn adapter.TCPConn) {
defer originConn.Close() defer originConn.Close()
@@ -62,7 +60,7 @@ func pipe(origin, remote net.Conn) error {
if err := copyBuffer(remote, origin); err != nil { if err := copyBuffer(remote, origin); err != nil {
leftErr = errors.Join(leftErr, err) leftErr = errors.Join(leftErr, err)
} }
remote.SetReadDeadline(time.Now().Add(_tcpWaitTimeout)) remote.SetReadDeadline(time.Now().Add(tcpWaitTimeout))
}() }()
go func() { go func() {
@@ -70,7 +68,7 @@ func pipe(origin, remote net.Conn) error {
if err := copyBuffer(origin, remote); err != nil { if err := copyBuffer(origin, remote); err != nil {
rightErr = errors.Join(rightErr, err) rightErr = errors.Join(rightErr, err)
} }
origin.SetReadDeadline(time.Now().Add(_tcpWaitTimeout)) origin.SetReadDeadline(time.Now().Add(tcpWaitTimeout))
}() }()
wg.Wait() wg.Wait()