Sun, 10 Jun 2007 16:01:26 +0000
Initial commit:
* Created tree structure
* Committed current version
0 | 1 | -- Tests Copas with a simple Echo server |
2 | -- | |
3 | -- Run the test file and the connect to the server by telnet on the used port | |
4 | -- to stop the test just send the command "quit" | |
5 | ||
6 | require"luaevent" | |
7 | require"socket" | |
8 | local function echoHandler(skt) | |
9 | while true do | |
10 | print(skt) | |
11 | local data,ret = luaevent.receive(skt, 10) | |
12 | print("GOT: ", data, ret) | |
13 | if data == "quit" or ret == 'closed' then | |
14 | break | |
15 | end | |
16 | luaevent.send(skt, data) | |
17 | end | |
18 | print("DONE") | |
19 | end | |
20 | local function setupHook(thread) | |
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)) | |
25 | server:settimeout(0) | |
26 | setupHook() | |
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) | |
34 | luaevent.loop() |