diff options
author | Thomas Harning Jr <harningt@gmail.com> | 2007-06-10 16:01:26 +0000 |
---|---|---|
committer | Thomas Harning Jr <harningt@gmail.com> | 2007-06-10 16:01:26 +0000 |
commit | ca61614b981fff436b50caabc2e61d4d962348b7 (patch) | |
tree | 23f812dd41a0a58f24513eade898ddaaf3614065 /luaevent/test/test.lua | |
download | luaevent-prosody-ca61614b981fff436b50caabc2e61d4d962348b7.tar.gz luaevent-prosody-ca61614b981fff436b50caabc2e61d4d962348b7.zip |
Initial commit:
* Created tree structure
* Committed current version
Diffstat (limited to 'luaevent/test/test.lua')
-rw-r--r-- | luaevent/test/test.lua | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/luaevent/test/test.lua b/luaevent/test/test.lua new file mode 100644 index 0000000..1bcd173 --- /dev/null +++ b/luaevent/test/test.lua @@ -0,0 +1,34 @@ +-- Tests Copas with a simple Echo server +-- +-- Run the test file and the connect to the server by telnet on the used port +-- to stop the test just send the command "quit" + +require"luaevent" +require"socket" +local function echoHandler(skt) + while true do + print(skt) + local data,ret = luaevent.receive(skt, 10) + print("GOT: ", data, ret) + if data == "quit" or ret == 'closed' then + break + end + luaevent.send(skt, data) + end + print("DONE") +end +local function setupHook(thread) + if not thread then debug.sethook(function(event) print("TRACE >: ", debug.getinfo(2, 'n').name) end, 'c') + else debug.sethook(thread, function(event) print("TRACE ", thread,">: ", debug.getinfo(2, 'n').name) end, 'c') end +end +local server = assert(socket.bind("localhost", 20000)) +server:settimeout(0) +setupHook() +local coro = coroutine.create +coroutine.create = function(...) + local ret = coro(...) + setupHook(ret) + return ret +end +luaevent.addserver(server, echoHandler) +luaevent.loop() |