-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtcp.go
50 lines (45 loc) · 777 Bytes
/
tcp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package socks5
import (
"io"
"net"
"time"
)
func (req *Request) connect(conn net.Conn) {
resp := genCMDResp(req.clt.LocalAddr())
if _, e := req.clt.Write(resp); e != nil {
req.cancel()
req.errs <- e
return
}
// Cancel Deadline
_ = req.clt.SetDeadline(time.Time{})
// Pipe Connection
go func() {
defer conn.Close()
defer req.cancel()
_, e := io.Copy(conn, req.clt)
if e != nil {
select {
case <-req.ctx.Done():
return
default:
// req.errs <- e
// some obvious errors, ignore.
}
}
}()
go func() {
defer conn.Close()
defer req.cancel()
_, e := io.Copy(req.clt, conn)
if e != nil {
select {
case <-req.ctx.Done():
return
default:
// req.errs <- e
// some obvious errors, ignore.
}
}
}()
}