Projects STRLCPY tun2socks Commits 2c51a656
🤬
  • ■ ■ ■ ■ ■ ■
    engine/engine.go
    skipped 122 lines
    123 123   log.Infof("[DIALER] set fwmark: %#x", k.Mark)
    124 124   }
    125 125   
     126 + if k.TCPWaitTimeout > 0 {
     127 + tunnel.SetTCPWaitTimeout(k.TCPWaitTimeout)
     128 + }
     129 + 
    126 130   if k.UDPTimeout > 0 {
    127 131   if k.UDPTimeout < time.Second {
    128 132   return errors.New("invalid udp timeout value")
    skipped 112 lines
  • ■ ■ ■ ■ ■
    engine/key.go
    skipped 12 lines
    13 13   TCPModerateReceiveBuffer bool `yaml:"tcp-moderate-receive-buffer"`
    14 14   TCPSendBufferSize string `yaml:"tcp-send-buffer-size"`
    15 15   TCPReceiveBufferSize string `yaml:"tcp-receive-buffer-size"`
     16 + TCPWaitTimeout time.Duration `yaml:"tcp-wait-timeout"`
    16 17   UDPRelayBufferSize string `yaml:"udp-relay-buffer-size"`
    17 18   UDPTimeout time.Duration `yaml:"udp-timeout"`
    18 19   TUNPreUp string `yaml:"tun-pre-up"`
    skipped 3 lines
  • ■ ■ ■ ■ ■
    main.go
    skipped 36 lines
    37 37   flag.StringVar(&key.TCPReceiveBufferSize, "tcp-rcvbuf", "", "Set TCP receive buffer size for netstack")
    38 38   flag.StringVar(&key.UDPRelayBufferSize, "udp-rlybuf", "", "Set UDP relay buffer size for tunnel")
    39 39   flag.BoolVar(&key.TCPModerateReceiveBuffer, "tcp-auto-tuning", false, "Enable TCP receive buffer auto-tuning")
     40 + flag.DurationVar(&key.TCPWaitTimeout, "tcp-wait-timeout", 0, "Set timeout before closing each TCP connection")
    40 41   flag.StringVar(&key.TUNPreUp, "tun-pre-up", "", "Execute a command before TUN device setup")
    41 42   flag.StringVar(&key.TUNPostUp, "tun-post-up", "", "Execute a command after TUN device setup")
    42 43   flag.BoolVar(&versionFlag, "version", false, "Show version and then quit")
    skipped 32 lines
  • ■ ■ ■ ■ ■ ■
    tunnel/tcp.go
    skipped 15 lines
    16 16   "github.com/xjasonlyu/tun2socks/v2/tunnel/statistic"
    17 17  )
    18 18   
    19  -const (
    20  - tcpWaitTimeout = 5 * time.Second
    21  -)
     19 +var _tcpWaitTimeout = 5 * time.Second
     20 + 
     21 +func SetTCPWaitTimeout(t time.Duration) {
     22 + _tcpWaitTimeout = t
     23 +}
    22 24   
    23 25  func handleTCPConn(localConn adapter.TCPConn) {
    24 26   defer localConn.Close()
    skipped 35 lines
    60 62   if err := copyBuffer(right, left); err != nil {
    61 63   leftErr = errors.Join(leftErr, err)
    62 64   }
    63  - right.SetReadDeadline(time.Now().Add(tcpWaitTimeout))
     65 + right.SetReadDeadline(time.Now().Add(_tcpWaitTimeout))
    64 66   }()
    65 67   
    66 68   go func() {
    skipped 1 lines
    68 70   if err := copyBuffer(left, right); err != nil {
    69 71   rightErr = errors.Join(rightErr, err)
    70 72   }
    71  - left.SetReadDeadline(time.Now().Add(tcpWaitTimeout))
     73 + left.SetReadDeadline(time.Now().Add(_tcpWaitTimeout))
    72 74   }()
    73 75   
    74 76   wg.Wait()
    skipped 25 lines
Please wait...
Page is in error, reload to recover