-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtcp_handle_signals.go
62 lines (54 loc) · 1.2 KB
/
tcp_handle_signals.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
51
52
53
54
55
56
57
58
59
60
61
62
package server
import (
"fmt"
"io"
"net"
"time"
"github.com/google/uuid"
"github.com/izikaj/iziproxy/shared"
)
func onTCPRequest(core *Server, conn *shared.Connection, ruuid uuid.UUID) error {
var pack *ProxyPack
var ok bool
core.Lock()
pack, ok = core.pool[ruuid]
core.Unlock()
if !ok {
return nil
}
msg, err := shared.Commander.MakeRequest(pack.Request)
err = conn.SendMessage(msg)
if err != nil {
if err == io.EOF {
fmt.Println("W: CLIENT DISCONNECTED (EOF)", err)
return err
}
switch err.(type) {
case net.Error:
fmt.Println("W: CLIENT DISCONNECTED (EPIPE)", err)
return err
}
fmt.Println("SEND REQUEST ERROR", err)
}
return nil
}
func handleTCPSignals(core *Server, conn *shared.Connection, cable *Cable) {
for {
select {
case ruuid := <-cable.spaceSignal:
onTCPRequest(core, conn, ruuid)
case ruuid := <-core.spaceSignal:
onTCPRequest(core, conn, ruuid)
case <-time.Tick(60 * time.Second):
msg, err := shared.Commander.MakePing()
err = conn.SendMessage(msg)
if err == nil {
fmt.Println("PING ERROR!!!", conn.RemoteAddr())
return
}
case err := <-cable.ufoSignal:
fmt.Printf("ufoSignal [%q], %v\n", err, err.Error())
return
}
}
}