From 35ac0581fa8e21502283480b99fc67ed7d46dc3b Mon Sep 17 00:00:00 2001 From: Thomas Harning Jr Date: Mon, 11 Jun 2007 01:08:59 +0000 Subject: * 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. --- luaevent/test/testClient.lua | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'luaevent/test/testClient.lua') 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() -- cgit v1.2.3