-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtabSimpleClient.lua
More file actions
99 lines (80 loc) · 2.27 KB
/
tabSimpleClient.lua
File metadata and controls
99 lines (80 loc) · 2.27 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
-- author cs
-- email 04nycs@gmail.com
-- https://github.com/ThinEureka/tabMachine
-- created on Oct 18 2022
local tabSocket = require("tabMachine.tabSocket")
local tabSimpleClient = nil
tabSimpleClient = _{
tabName = "tabSimpleClient",
s1 = function(c, params)
c._nickName = "client"
c._tabSocket = c:call(tabSocket, "socket", nil, 15)
c._tabCmdHandler = c:call(params.cmdHandler(params.handlerParams), "cmdHandler")
end,
s2 = function(c)
c:suspend("s3")
end,
s3 = function(c, ip, port, timeout, tabErrHandler)
c:call(c._tabSocket:connect(ip, port, timeout), "s4", {"isSuccess", "err"})
end,
s5 = function(c)
if c.isSuccess then
c:call(tabSimpleClient.tabWorking(), "s6")
else
c:start("s2")
end
end,
s7 = function(c)
c._tabSocket:disconnect()
c:start("s2")
end,
-- event & inner
event = g_t.empty_event,
inner = {
tabSocket = function(c)
return c._tabSocket
end,
tabCmdHandler = function(c)
return c._tabCmdHandler
end,
service = function(c)
return c
end,
},
-- public:
connect = function(c, ip, port, timeout, tabErrHandler)
c:resume("s3", ip, port, timeout, tabErrHandler)
return c:tabProxy("s4", true)
end,
getTabSocket = function(c)
return c._tabSocket
end,
tabInWorking = function(c, stopHostWhenStop)
local sub = c:getSub("s6")
if sub == nil then
return nil
else
return sub:tabProxy(nil, stopHostWhenStop)
end
end,
sendRpc = function(c, ...)
return c._tabCmdHandler:sendRpc(...)
end,
sendRequest = function(c, ...)
return c._tabCmdHandler:sendRequest(...)
end,
}
tabSimpleClient.tabWorking = _{
s1 = function(c)
c:call(c:_("tabSocket"):tabInState(tabSocket.STATE.CONNECTED), "s2")
local tabCmdHandler = c:_("tabCmdHandler")
c:call(c:_("tabSocket"):tabPullSegments(tabCmdHandler.decodeSegment, function(msg)
tabCmdHandler:onNewSegment(msg)
end), "pullMsg")
end,
s3 = function(c)
c:stop()
end,
event = g_t.empty_event,
}
return tabSimpleClient