lua-users home
lua-l archive

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


Andre,

I hope to complete a swiss-army knife application that handles telnet
(to a lua prompt), httpd (to static pages and lua-cgi), and a custom
sql-over-socket protocol I'm playing with.

Down the road, I want to add serial (rs-232) support. I've messed with
this before after talking to Diego, but haven't done any work lately,
so I'll resort to a pseudo-terminal/rs-232 to socket tunnel I wrote in
C years ago to handle the task (this solution is creaky, but works
well under Windows as well.)

One day, I'll have my ideal system... LuaOS... like UNIX, but instead
of "everything is a file", it'll be "everything is a table"... ;-)

Thanks for the clarification.
-joe

On Thu,  3 Mar 2005 12:03:52 -0300, Andre Carregal
<carregal@fabricadigital.com.br> wrote:
> > 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
> 
> bind(...)
> while true
>  select(...)
>  skt = accept()
>  handle(skt)
> end
> 
> 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
> 
> bind(...)
> while true
>  select(...)
>  skt = accept()
>  newthread(handle(skt))
> end
> 
> (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
> 
> copas.loop()
> 
> 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
> 
> 


-- 
If it ain't broke, break it.  How else are you going to figure out how it works?