diff options
Diffstat (limited to 'luaevent/test')
-rw-r--r-- | luaevent/test/test.lua | 33 | ||||
-rw-r--r-- | luaevent/test/testClient.lua | 27 |
2 files changed, 28 insertions, 32 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 diff --git a/luaevent/test/testClient.lua b/luaevent/test/testClient.lua index b6dfa44..0557230 100644 --- a/luaevent/test/testClient.lua +++ b/luaevent/test/testClient.lua @@ -1,15 +1,22 @@ 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 +end -local function func() - print("ACTIVATED") - local sock = socket.tcp() - --sock: +local function func(sock) sock = luaevent.wrap(sock) - print(assert(sock:connect("localhost", 20000))) - for i = 1, 100000 do assert(sock:send("Greet me ")) assert(sock:receive(10)) collectgarbage() end + assert(sock:connect("localhost", 20000)) + for i = 1, 10 do + for z = 1, 100 do + assert(sock:send("Greet me ")) + end + assert(sock:receive(10 * 100)) + end end - -luaevent.addthread(func) - -luaevent.loop()
\ No newline at end of file +for i = 1, 1020 do + local sock = assert(socket.tcp()) + luaevent.addthread(sock, func, sock) +end +luaevent.loop() |