lua-users home
lua-l archive

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


On 1/26/06, Jeff Sheets <jeff.sheets@insightbb.com> wrote:
> Have a look at the way the Xavante server implemented in Lua at
> keplerproject.org uses copas.  IIRC, you can create a copas socket that
> wraps a luaSocket, but has the same interface (at least the same
> interface needed after you wrap it).
>
> If Copas doesn't actually do this, it would be extremely easy to add it
> in.

I see how it is done in Xavante by wrapping luaSocket, but the Ruby
scheme is better. Every call that can block is wrapped down inside of
it's implementation in the run-time.  Ruby wouldn't expose the
blocking luaSocket API, they would only expose the wrapped API. The
big win is that the wrapping is transparent to the user, that makes it
easy to use.

Wrapping of blocking functions is key to how Ruby implements threads.
Green threads don't work if an application thread can get stuck in a
blocking system call. By wrapping everything in the run-time Ruby
makes sure you can't get stuck.

So in Ruby when you read() from a socket, you are actually doing a
read()=EAGAIN, running other threads, wait_poll(), got some data,
return. Same thing for read/write from a file.

--
Jon Smirl
jonsmirl@gmail.com