forked from cloudwu/skynet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpingserver.lua
53 lines (44 loc) · 823 Bytes
/
pingserver.lua
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
local skynet = require "skynet"
local queue = require "skynet.queue"
local snax = require "snax"
local i = 0
local hello = "hello"
function response.ping(hello)
skynet.sleep(100)
return hello
end
-- response.sleep and accept.hello share one lock
local lock
function accept.sleep(queue, n)
if queue then
lock(
function()
print("queue=",queue, n)
skynet.sleep(n)
end)
else
print("queue=",queue, n)
skynet.sleep(n)
end
end
function accept.hello()
lock(function()
i = i + 1
print (i, hello)
end)
end
function accept.exit(...)
snax.exit(...)
end
function response.error()
error "throw an error"
end
function init( ... )
print ("ping server start:", ...)
snax.enablecluster() -- enable cluster call
-- init queue
lock = queue()
end
function exit(...)
print ("ping server exit:", ...)
end