lua-users home
lua-l archive

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

[Trying to follow everyone's speed and keeping the "(long post)" necessity]

> I assume a non-blocking accept().

We too.

> You forgot the listening socket(s), yes a map is needed of sockets ready to read
> remember that the accepting socket would be expected to be in this list and
> the accepting socket should be the first one serviced, the accepting socket
> should also be checked (again) before the write coroutine is invoked. That is,
> each time you check one of the lists, check the listener first, lest the listen
> queue explodes. 

Good point, thanks for pointing that out.

> I would restate the transition from reading mode to writng mode as (assuming a
> request/response type server):
> when the read is complete the socket is added to the "want-to-send" list or
> the "want-to-close" list. Methinks its simpler if this happens in the
> "read" routine.
> (i.e. Chaining) 

I agree that this would make protocols like HTTP easier to handle, but one of the ideas of this experiment with Xavante is how far we can go with a reusable dispatcher. Assuming it ever gets done, do you think your chaining proposal would work with FTP or SMTP for example? More on this below.

> I presume that you assume that the receiving routine is maintaining a
> state and readbuffer
> for each connection? Yes/No?

Not sure if answering your question, but Xavante is currently being separated in two basic modules. One is a tentatively protocol independent dispatcher (Copas) on the lines of Diego recent post and the other is a HTTP handler. In this view Xavante would be a very small module that would just do something like:


copas.addserver({port = xx, ... , handler = httphandler})

This thing called Copas (coroutine oriented portable assynchronous services) would offer methods to implement the protocol handlers and to call the dispatcher:

coxpcall and copcall - xpcall and pcall implemented with coroutines
step - executes one listening step of the dispatching loop
loop - executes forever the dispatcher
send, receive - socket methods that yield on timeouts
read, write - file methods that yield during the operations (not necessarily timeouts)

If someone recognizes Python's asyncore ideas here that would be no coincidence, but in Copas the "p" (portable) is considered mandatory since we are trying to see how far we can go using Lua only.

> PS I struggle with co-routines.

Doesn't everyone? :o)

Our plans with the Copas abstraction are simplifying the life of the handlers writers. For example, in Xavante the HTTPHandler and CGILua do not know that they are being executed by coroutines. As long as HTTPHandler calls Copas I/O methods and CGILua calls HTTPHandler SAPI methods everything works fine.

If someone would be bold (or maybe just naive) enough to try Copas with other protocols please let me know. Theoretically one could add different servers to Copas and execute them step by step or continuously. Error handling would have to be nice to both methods, but that will be a future quest for Copas...

Once again I'd like to thank the unvaluable help offered from Diego, David, Mike and others.

Andre Carregal