test/test.lua

Wed, 03 Mar 2010 18:19:20 -0600

author
James Snyder <jbsnyder@fanplastic.org>
date
Wed, 03 Mar 2010 18:19:20 -0600
changeset 101
f5369fe8f107
parent 13
3e2ea1e7b2e8
permissions
-rw-r--r--

Changes to compile on OS X.

- BSD version of install doesn't have -D flag
- stdlib.h should include malloc defs (malloc.h is obsolete)

-- 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 oldPrint = print
print = function(...)
	oldPrint("SRV", ...)
end

local function echoHandler(skt)
  while true do
    local data,ret = luaevent.receive(skt, 10)
    --print("GOT: ", data, ret)
    if data == "quit" or ret == 'closed' then
      break
    end
    luaevent.send(skt, data)
    collectgarbage()
  end
  skt:close()
  --print("DONE")
end
local server = assert(socket.bind("localhost", 20000))
server:settimeout(0)
local coro = coroutine.create
coroutine.create = function(...)
	local ret = coro(...)
	return ret
end
luaevent.addserver(server, echoHandler)
luaevent.loop()

mercurial