aboutsummaryrefslogtreecommitdiffstats
path: root/luaevent/test
diff options
context:
space:
mode:
authorThomas Harning Jr <harningt@gmail.com>2007-08-18 20:57:33 +0000
committerThomas Harning Jr <harningt@gmail.com>2007-08-18 20:57:33 +0000
commit663fa798eeda2d1c66351d707c2f7e9cb2a9cf00 (patch)
treebe8a04fdf08eb4865dc55f6c9f7032d9ba93b403 /luaevent/test
parentdbea9370eb58cdc3cbd1b12d8c8735582370cd6e (diff)
downloadluaevent-prosody-663fa798eeda2d1c66351d707c2f7e9cb2a9cf00.tar.gz
luaevent-prosody-663fa798eeda2d1c66351d707c2f7e9cb2a9cf00.zip
* Committing what will be version 0.1.2
Main feature: Callback/coroutine issues resolved as described in COROUTINE_MANAGEMENT
Diffstat (limited to 'luaevent/test')
-rw-r--r--luaevent/test/test.lua34
-rw-r--r--luaevent/test/testClient.lua38
2 files changed, 36 insertions, 36 deletions
diff --git a/luaevent/test/test.lua b/luaevent/test/test.lua
index fd9919d..412857e 100644
--- a/luaevent/test/test.lua
+++ b/luaevent/test/test.lua
@@ -5,20 +5,30 @@
require"luaevent"
require"socket"
-local function echoHandler(skt)
- while true do
- local data,ret = luaevent.receive(skt, 10)
- if data == "quit" or ret == 'closed' or not data then
- break
- end
- --collectgarbage()
- if not luaevent.send(skt, data) then return end
- end
- if skt then skt:close() end
+local oldPrint = print
+print = function(...)
+ oldPrint("SRV", ...)
end
+local function echoHandler(skt)
+ while true do
+ local data,ret = luaevent.receive(skt, 10)
+ --print("GOT: ", data, ret)
+ if data == "quit" or ret == 'closed' then
+ break
+ end
+ luaevent.send(skt, data)
+ collectgarbage()
+ end
+ skt:close()
+ --print("DONE")
+end
local server = assert(socket.bind("localhost", 20000))
server:settimeout(0)
-
+local coro = coroutine.create
+coroutine.create = function(...)
+ local ret = coro(...)
+ return ret
+end
luaevent.addserver(server, echoHandler)
-luaevent.loop() \ No newline at end of file
+luaevent.loop()
diff --git a/luaevent/test/testClient.lua b/luaevent/test/testClient.lua
index 8d14887..fbbcf87 100644
--- a/luaevent/test/testClient.lua
+++ b/luaevent/test/testClient.lua
@@ -1,29 +1,19 @@
require"luaevent"
require"socket"
-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
+local oldPrint = print
+print = function(...)
+ oldPrint("CLT", ...)
end
-local count = 100
-local function func(sock)
+
+local function func()
+ print("ACTIVATED")
+ local sock = socket.tcp()
+ --sock:
sock = luaevent.wrap(sock)
- assert(sock:connect("localhost", 20000))
- for i = 1, 2 do
- local maxZ = 10
- for z = 1, maxZ do
- assert(sock:send("Greet me "))
- end
- assert(sock:receive(10 * maxZ))
- end
- if skt then skt:close() end
- count = count - 1
- if count > 0 then
- --local sock = assert(socket.tcp())
- --luaevent.addthread(sock, func, sock)
- end
+ print(assert(sock:connect("localhost", 20000)))
+ for i = 1, 100 do assert(sock:send("Greet me ")) assert(sock:receive(10)) collectgarbage() end
end
-for i = 1, 500 do
- local sock = assert(socket.tcp())
- luaevent.addthread(sock, func, sock)
-end
-luaevent.loop()
+
+luaevent.addthread(func)
+
+luaevent.loop() \ No newline at end of file