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.

-- Tests Copas with a simple Echo server
--
-- Run the test file and the connect to the server by telnet on the used port
-- to stop the test just send the command "quit"

require"luaevent"
require"socket"
local function echoHandler(skt)
	while true do
		local data,ret = luaevent.receive(skt, 10)
		if data == "quit" or ret == 'closed' or not data then
			break
		end
		--collectgarbage()
		if not luaevent.send(skt, data) then return end
	end
	if skt then skt:close() end
end

local server = assert(socket.bind("localhost", 20000))
server:settimeout(0)

luaevent.addserver(server, echoHandler)
luaevent.loop()

mercurial