aboutsummaryrefslogtreecommitdiffstats
path: root/luaevent/test/test.lua
diff options
context:
space:
mode:
authorThomas Harning Jr <harningt@gmail.com>2007-06-11 01:08:59 +0000
committerThomas Harning Jr <harningt@gmail.com>2007-06-11 01:08:59 +0000
commit35ac0581fa8e21502283480b99fc67ed7d46dc3b (patch)
treeedb989b681d95ca16caaebb55712cec6d23a1999 /luaevent/test/test.lua
parent9839406cc22bd47bbf4bd82d73860f9f7e270155 (diff)
downloadluaevent-prosody-35ac0581fa8e21502283480b99fc67ed7d46dc3b.tar.gz
luaevent-prosody-35ac0581fa8e21502283480b99fc67ed7d46dc3b.zip
* Completed mostly working version
* Moved to a mode where addevent calls a callback rather than it being instantiated within. * If the callback returns -1, then no event is ever setup * Otherwise the integer value is used to setup the event * This allows for using coroutine.wrap rather than a cooked-up wrapper * Tests work, although there are a few remaining issues: * Need to figure a good way of preserving the event object, not sure if current method is good enough, since the socket is the only anchor, and it is only held inside the coro.. circular reference, something that Lua 'handles' well. * Doing more than the maximum sockets the process is allows causes strangeness to occur in libevent.. somehow it is getting around to epoll_add which is causing valgrind to barf.
Diffstat (limited to 'luaevent/test/test.lua')
-rw-r--r--luaevent/test/test.lua33
1 files changed, 11 insertions, 22 deletions
diff --git a/luaevent/test/test.lua b/luaevent/test/test.lua
index 1bcd173..f7a44da 100644
--- a/luaevent/test/test.lua
+++ b/luaevent/test/test.lua
@@ -6,29 +6,18 @@
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
+ while true do
+ local data,ret = luaevent.receive(skt, 10)
+ if data == "quit" or ret == 'closed' then
+ break
+ end
+ --collectgarbage()
+ luaevent.send(skt, data)
+ 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()
+luaevent.loop() \ No newline at end of file