luaevent/test/testClient.lua

Mon, 11 Jun 2007 01:08:59 +0000

author
Thomas Harning Jr <harningt@gmail.com>
date
Mon, 11 Jun 2007 01:08:59 +0000
changeset 2
01b3a96ae760
parent 0
f2e807614be9
child 10
88ce07d62597
permissions
-rw-r--r--

* 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.

0
f2e807614be9 Initial commit:
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
1 require"luaevent"
f2e807614be9 Initial commit:
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
2 require"socket"
2
01b3a96ae760 * Completed mostly working version
Thomas Harning Jr <harningt@gmail.com>
parents: 0
diff changeset
3 local function setupHook(thread)
01b3a96ae760 * Completed mostly working version
Thomas Harning Jr <harningt@gmail.com>
parents: 0
diff changeset
4 if not thread then debug.sethook(function(event) print("TRACE >: ", debug.getinfo(2, 'n').name) end, 'c')
01b3a96ae760 * Completed mostly working version
Thomas Harning Jr <harningt@gmail.com>
parents: 0
diff changeset
5 else debug.sethook(thread, function(event) print("TRACE ", thread,">: ", debug.getinfo(2, 'n').name) end, 'c') end
0
f2e807614be9 Initial commit:
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
6 end
f2e807614be9 Initial commit:
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
7
2
01b3a96ae760 * Completed mostly working version
Thomas Harning Jr <harningt@gmail.com>
parents: 0
diff changeset
8 local function func(sock)
01b3a96ae760 * Completed mostly working version
Thomas Harning Jr <harningt@gmail.com>
parents: 0
diff changeset
9 sock = luaevent.wrap(sock)
01b3a96ae760 * Completed mostly working version
Thomas Harning Jr <harningt@gmail.com>
parents: 0
diff changeset
10 assert(sock:connect("localhost", 20000))
01b3a96ae760 * Completed mostly working version
Thomas Harning Jr <harningt@gmail.com>
parents: 0
diff changeset
11 for i = 1, 10 do
01b3a96ae760 * Completed mostly working version
Thomas Harning Jr <harningt@gmail.com>
parents: 0
diff changeset
12 for z = 1, 100 do
01b3a96ae760 * Completed mostly working version
Thomas Harning Jr <harningt@gmail.com>
parents: 0
diff changeset
13 assert(sock:send("Greet me "))
01b3a96ae760 * Completed mostly working version
Thomas Harning Jr <harningt@gmail.com>
parents: 0
diff changeset
14 end
01b3a96ae760 * Completed mostly working version
Thomas Harning Jr <harningt@gmail.com>
parents: 0
diff changeset
15 assert(sock:receive(10 * 100))
01b3a96ae760 * Completed mostly working version
Thomas Harning Jr <harningt@gmail.com>
parents: 0
diff changeset
16 end
01b3a96ae760 * Completed mostly working version
Thomas Harning Jr <harningt@gmail.com>
parents: 0
diff changeset
17 end
01b3a96ae760 * Completed mostly working version
Thomas Harning Jr <harningt@gmail.com>
parents: 0
diff changeset
18 for i = 1, 1020 do
01b3a96ae760 * Completed mostly working version
Thomas Harning Jr <harningt@gmail.com>
parents: 0
diff changeset
19 local sock = assert(socket.tcp())
01b3a96ae760 * Completed mostly working version
Thomas Harning Jr <harningt@gmail.com>
parents: 0
diff changeset
20 luaevent.addthread(sock, func, sock)
01b3a96ae760 * Completed mostly working version
Thomas Harning Jr <harningt@gmail.com>
parents: 0
diff changeset
21 end
01b3a96ae760 * Completed mostly working version
Thomas Harning Jr <harningt@gmail.com>
parents: 0
diff changeset
22 luaevent.loop()

mercurial