luaevent/test/test.lua

Wed, 13 Jun 2007 04:32:12 +0000

author
Thomas Harning Jr <harningt@gmail.com>
date
Wed, 13 Jun 2007 04:32:12 +0000
changeset 10
88ce07d62597
parent 2
01b3a96ae760
child 11
8339f6236a3c
permissions
-rw-r--r--

Setup management of socket create/close.
Recognized new bug: cannot create threads within threads... C contains reference to closed thread, not
global.

0
f2e807614be9 Initial commit:
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
1 -- Tests Copas with a simple Echo server
f2e807614be9 Initial commit:
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
2 --
f2e807614be9 Initial commit:
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
3 -- Run the test file and the connect to the server by telnet on the used port
f2e807614be9 Initial commit:
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
4 -- to stop the test just send the command "quit"
f2e807614be9 Initial commit:
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
5
f2e807614be9 Initial commit:
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
6 require"luaevent"
f2e807614be9 Initial commit:
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
7 require"socket"
f2e807614be9 Initial commit:
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
8 local function echoHandler(skt)
2
01b3a96ae760 * Completed mostly working version
Thomas Harning Jr <harningt@gmail.com>
parents: 0
diff changeset
9 while true do
01b3a96ae760 * Completed mostly working version
Thomas Harning Jr <harningt@gmail.com>
parents: 0
diff changeset
10 local data,ret = luaevent.receive(skt, 10)
10
88ce07d62597 Setup management of socket create/close.
Thomas Harning Jr <harningt@gmail.com>
parents: 2
diff changeset
11 if data == "quit" or ret == 'closed' or not data then
2
01b3a96ae760 * Completed mostly working version
Thomas Harning Jr <harningt@gmail.com>
parents: 0
diff changeset
12 break
01b3a96ae760 * Completed mostly working version
Thomas Harning Jr <harningt@gmail.com>
parents: 0
diff changeset
13 end
01b3a96ae760 * Completed mostly working version
Thomas Harning Jr <harningt@gmail.com>
parents: 0
diff changeset
14 --collectgarbage()
10
88ce07d62597 Setup management of socket create/close.
Thomas Harning Jr <harningt@gmail.com>
parents: 2
diff changeset
15 if not luaevent.send(skt, data) then return end
2
01b3a96ae760 * Completed mostly working version
Thomas Harning Jr <harningt@gmail.com>
parents: 0
diff changeset
16 end
10
88ce07d62597 Setup management of socket create/close.
Thomas Harning Jr <harningt@gmail.com>
parents: 2
diff changeset
17 if skt then skt:close() end
0
f2e807614be9 Initial commit:
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
18 end
2
01b3a96ae760 * Completed mostly working version
Thomas Harning Jr <harningt@gmail.com>
parents: 0
diff changeset
19
0
f2e807614be9 Initial commit:
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
20 local server = assert(socket.bind("localhost", 20000))
f2e807614be9 Initial commit:
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
21 server:settimeout(0)
2
01b3a96ae760 * Completed mostly working version
Thomas Harning Jr <harningt@gmail.com>
parents: 0
diff changeset
22
0
f2e807614be9 Initial commit:
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
23 luaevent.addserver(server, echoHandler)
2
01b3a96ae760 * Completed mostly working version
Thomas Harning Jr <harningt@gmail.com>
parents: 0
diff changeset
24 luaevent.loop()

mercurial