| skipped 4 lines |
5 | 5 | | "io" |
6 | 6 | | "net" |
7 | 7 | | "sync" |
8 | | - | "syscall" |
9 | 8 | | "time" |
10 | 9 | | |
11 | 10 | | "github.com/xjasonlyu/tun2socks/v2/common/pool" |
| skipped 4 lines |
16 | 15 | | "github.com/xjasonlyu/tun2socks/v2/tunnel/statistic" |
17 | 16 | | ) |
18 | 17 | | |
| 18 | + | // _tcpWaitTimeout is the default timeout to wait after closing each TCP connection. |
19 | 19 | | var _tcpWaitTimeout = 5 * time.Second |
20 | 20 | | |
21 | 21 | | func SetTCPWaitTimeout(t time.Duration) { |
| skipped 60 lines |
82 | 82 | | defer pool.Put(buf) |
83 | 83 | | |
84 | 84 | | _, err := io.CopyBuffer(dst, src, buf) |
85 | | - | if err != nil && !isIgnorable(err) { |
86 | | - | return err |
87 | | - | } |
88 | | - | return nil |
89 | | - | } |
90 | | - | |
91 | | - | func isIgnorable(err error) bool { |
92 | | - | if ne, ok := err.(net.Error); ok && ne.Timeout() { |
93 | | - | return true /* ignore I/O timeout */ |
94 | | - | } else if errors.Is(err, syscall.EPIPE) { |
95 | | - | return true /* ignore broken pipe */ |
96 | | - | } else if errors.Is(err, syscall.ECONNRESET) { |
97 | | - | return true /* ignore connection reset by peer */ |
98 | | - | } |
99 | | - | return false |
| 85 | + | return err |
100 | 86 | | } |
101 | 87 | | |