luaevent/test/testClient.lua

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

mercurial