lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

> Just started messing with luahttpd (thanks kindly to y'all) to better
> understand copas.

Thanks for trying it! :o)

> require("socket.url")
> local url = socket.url
> Also, there's a reference to "copas.skt_wrap". I believe this is
> "copas.wrap" in the latest copas.

You are right, luahttp 0.5b is using an old version of copas.

As some may have already noticed, luahttpd and Xavante has merged in a single project (Xavante) using Javier's HTTP Engine and Kepler's Copas and configuration management.

We are about to release Xavante 1.1 and a brief tutorial on Copas. Just to give you some directions here is the draft of it:

Most servers use a dispatcher loop like

while true
 skt = accept()

but this causes the server to handle just one connection at a time and to solve this the solution one may use threads. The loop then becomes something like

while true
 skt = accept()

(BTW, that is what luahttpd was doing before using Copas, the threads were handled by LuaThreads)

Copas allows multitasking without threads using coroutines and implements the loop for you. All you have to do to use Copas is register your server and handle:

server = bind(...)
copas.addserver(server, handle)

Your handler has to be changed to use Copas sockets instead of LuaSocket sockets, that's where copas.wrap(skt) goes. It returns a socket that implements the same interface as LuaSockets' but is able to yield on timeouts.

And to run the dispatcher call


If you look at httpengine.lua it does the registration with httpd.register() and the handler is implemented by connection().

I hope that helps a bit. May I ask if you are planning to use Copas to handle anything other than HTTP?

Andre Carregal