From dbea9370eb58cdc3cbd1b12d8c8735582370cd6e Mon Sep 17 00:00:00 2001 From: Thomas Harning Jr Date: Wed, 13 Jun 2007 04:32:12 +0000 Subject: Setup management of socket create/close. Recognized new bug: cannot create threads within threads... C contains reference to closed thread, not global. --- luaevent/test/test.lua | 5 +++-- luaevent/test/testClient.lua | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) (limited to 'luaevent/test') diff --git a/luaevent/test/test.lua b/luaevent/test/test.lua index f7a44da..fd9919d 100644 --- a/luaevent/test/test.lua +++ b/luaevent/test/test.lua @@ -8,12 +8,13 @@ require"socket" local function echoHandler(skt) while true do local data,ret = luaevent.receive(skt, 10) - if data == "quit" or ret == 'closed' then + if data == "quit" or ret == 'closed' or not data then break end --collectgarbage() - luaevent.send(skt, data) + if not luaevent.send(skt, data) then return end end + if skt then skt:close() end end local server = assert(socket.bind("localhost", 20000)) diff --git a/luaevent/test/testClient.lua b/luaevent/test/testClient.lua index 0557230..8d14887 100644 --- a/luaevent/test/testClient.lua +++ b/luaevent/test/testClient.lua @@ -4,18 +4,25 @@ 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 count = 100 local function func(sock) sock = luaevent.wrap(sock) assert(sock:connect("localhost", 20000)) - for i = 1, 10 do - for z = 1, 100 do + for i = 1, 2 do + local maxZ = 10 + for z = 1, maxZ do assert(sock:send("Greet me ")) end - assert(sock:receive(10 * 100)) + 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 end -for i = 1, 1020 do +for i = 1, 500 do local sock = assert(socket.tcp()) luaevent.addthread(sock, func, sock) end -- cgit v1.2.3