Newer
Older
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
package server
import (
"fmt"
"net"
"time"
)
type connectState struct {
fsm *FSM2
}
func newConnectState(fsm *FSM2) *connectState {
return &connectState{
fsm: fsm,
}
}
func (s *connectState) run() (state, string) {
for {
select {
case e := <-s.fsm.eventCh:
if e == ManualStop {
return s.manualStop()
}
continue
case <-s.fsm.connectRetryTimer.C:
s.connectRetryTimerExpired()
continue
case c := <-s.fsm.conCh:
s.connectionSuccess(c)
}
}
}
func (s *connectState) connectionSuccess(c net.Conn) (state, string) {
s.fsm.con = c
stopTimer(s.fsm.connectRetryTimer)
err := s.fsm.sendOpen()
if err != nil {
return newIdleState(s.fsm), fmt.Sprintf("Unable to send open: %v", err)
}
s.fsm.holdTimer = time.NewTimer(time.Minute * 4)
return newOpenSentState(s.fsm), "TCP connection succeeded"
}
func (s *connectState) connectRetryTimerExpired() {
s.fsm.resetConnectRetryTimer()
s.fsm.tcpConnect()
}
func (s *connectState) manualStop() (state, string) {
s.fsm.resetConnectRetryCounter()
stopTimer(s.fsm.connectRetryTimer)
return newIdleState(s.fsm), "Manual stop event"
}
func (s *connectState) cease() {
}