luaevent/test/testClient.lua

changeset 2
01b3a96ae760
parent 0
f2e807614be9
child 10
88ce07d62597
equal deleted inserted replaced
1:31c782cfe7fe 2:01b3a96ae760
1 require"luaevent" 1 require"luaevent"
2 require"socket" 2 require"socket"
3 3 local function setupHook(thread)
4 local function func() 4 if not thread then debug.sethook(function(event) print("TRACE >: ", debug.getinfo(2, 'n').name) end, 'c')
5 print("ACTIVATED") 5 else debug.sethook(thread, function(event) print("TRACE ", thread,">: ", debug.getinfo(2, 'n').name) end, 'c') end
6 local sock = socket.tcp()
7 --sock:
8 sock = luaevent.wrap(sock)
9 print(assert(sock:connect("localhost", 20000)))
10 for i = 1, 100000 do assert(sock:send("Greet me ")) assert(sock:receive(10)) collectgarbage() end
11 end 6 end
12 7
13 luaevent.addthread(func) 8 local function func(sock)
14 9 sock = luaevent.wrap(sock)
10 assert(sock:connect("localhost", 20000))
11 for i = 1, 10 do
12 for z = 1, 100 do
13 assert(sock:send("Greet me "))
14 end
15 assert(sock:receive(10 * 100))
16 end
17 end
18 for i = 1, 1020 do
19 local sock = assert(socket.tcp())
20 luaevent.addthread(sock, func, sock)
21 end
15 luaevent.loop() 22 luaevent.loop()

mercurial