mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2025-10-06 17:26:58 +08:00
@@ -123,10 +123,6 @@ func general(k *Key) error {
|
||||
log.Infof("[DIALER] set fwmark: %#x", k.Mark)
|
||||
}
|
||||
|
||||
if k.TCPWaitTimeout > 0 {
|
||||
tunnel.SetTCPWaitTimeout(k.TCPWaitTimeout)
|
||||
}
|
||||
|
||||
if k.UDPTimeout > 0 {
|
||||
if k.UDPTimeout < time.Second {
|
||||
return errors.New("invalid udp timeout value")
|
||||
|
@@ -13,8 +13,7 @@ type Key struct {
|
||||
TCPModerateReceiveBuffer bool `yaml:"tcp-moderate-receive-buffer"`
|
||||
TCPSendBufferSize string `yaml:"tcp-send-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"`
|
||||
TUNPostUp string `yaml:"tun-post-up"`
|
||||
UDPTimeout time.Duration `yaml:"udp-timeout"`
|
||||
}
|
||||
|
1
main.go
1
main.go
@@ -36,7 +36,6 @@ func init() {
|
||||
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.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.TUNPostUp, "tun-post-up", "", "Execute a command after TUN device setup")
|
||||
flag.BoolVar(&versionFlag, "version", false, "Show version and then quit")
|
||||
|
@@ -15,12 +15,10 @@ import (
|
||||
"github.com/xjasonlyu/tun2socks/v2/tunnel/statistic"
|
||||
)
|
||||
|
||||
// _tcpWaitTimeout is the default timeout to wait after closing each TCP connection.
|
||||
var _tcpWaitTimeout = 5 * time.Second
|
||||
|
||||
func SetTCPWaitTimeout(t time.Duration) {
|
||||
_tcpWaitTimeout = t
|
||||
}
|
||||
const (
|
||||
// tcpWaitTimeout implements a TCP half-close timeout.
|
||||
tcpWaitTimeout = 60 * time.Second
|
||||
)
|
||||
|
||||
func handleTCPConn(originConn adapter.TCPConn) {
|
||||
defer originConn.Close()
|
||||
@@ -62,7 +60,7 @@ func pipe(origin, remote net.Conn) error {
|
||||
if err := copyBuffer(remote, origin); err != nil {
|
||||
leftErr = errors.Join(leftErr, err)
|
||||
}
|
||||
remote.SetReadDeadline(time.Now().Add(_tcpWaitTimeout))
|
||||
remote.SetReadDeadline(time.Now().Add(tcpWaitTimeout))
|
||||
}()
|
||||
|
||||
go func() {
|
||||
@@ -70,7 +68,7 @@ func pipe(origin, remote net.Conn) error {
|
||||
if err := copyBuffer(origin, remote); err != nil {
|
||||
rightErr = errors.Join(rightErr, err)
|
||||
}
|
||||
origin.SetReadDeadline(time.Now().Add(_tcpWaitTimeout))
|
||||
origin.SetReadDeadline(time.Now().Add(tcpWaitTimeout))
|
||||
}()
|
||||
|
||||
wg.Wait()
|
||||
|
Reference in New Issue
Block a user