4 -- to stop the test just send the command "quit" |
4 -- to stop the test just send the command "quit" |
5 |
5 |
6 require"luaevent" |
6 require"luaevent" |
7 require"socket" |
7 require"socket" |
8 local function echoHandler(skt) |
8 local function echoHandler(skt) |
9 while true do |
9 while true do |
10 print(skt) |
10 local data,ret = luaevent.receive(skt, 10) |
11 local data,ret = luaevent.receive(skt, 10) |
11 if data == "quit" or ret == 'closed' then |
12 print("GOT: ", data, ret) |
12 break |
13 if data == "quit" or ret == 'closed' then |
13 end |
14 break |
14 --collectgarbage() |
15 end |
15 luaevent.send(skt, data) |
16 luaevent.send(skt, data) |
16 end |
17 end |
|
18 print("DONE") |
|
19 end |
17 end |
20 local function setupHook(thread) |
18 |
21 if not thread then debug.sethook(function(event) print("TRACE >: ", debug.getinfo(2, 'n').name) end, 'c') |
|
22 else debug.sethook(thread, function(event) print("TRACE ", thread,">: ", debug.getinfo(2, 'n').name) end, 'c') end |
|
23 end |
|
24 local server = assert(socket.bind("localhost", 20000)) |
19 local server = assert(socket.bind("localhost", 20000)) |
25 server:settimeout(0) |
20 server:settimeout(0) |
26 setupHook() |
21 |
27 local coro = coroutine.create |
|
28 coroutine.create = function(...) |
|
29 local ret = coro(...) |
|
30 setupHook(ret) |
|
31 return ret |
|
32 end |
|
33 luaevent.addserver(server, echoHandler) |
22 luaevent.addserver(server, echoHandler) |
34 luaevent.loop() |
23 luaevent.loop() |