lua-users home
lua-l archive

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

Jerome Vuarand wrote:
2009/11/3 Diego Nehab <>:
I agree getfd and setfd are not greatly thought out
features. That's why I call them hacks and that's why they
are not part of the documented API. They are there just for
debugging purposes and for people who want to use them at
their own risk.

The problem is that these functions can lead to confusion on
Windows, since socket objects are not file descriptors
Having them in the API would seem to indicate it is ok to
obtain a file descriptor from a file handle and then insert
them in a socket object. This would not work on Windows and
I don't like the idea of having this on the API.

Now, if what we are talking about functionality that allows
you to obtain this OS-dependent socket handle/descriptor and
create another LuaSocket object from it, we can discuss what
is the best API for it. It is a valid scenario that I had
not foreseen, and I'd be happy to add it to the library.

I couldn't agree more. Leaking low level concepts in a high level API
is likely to make it non-portable. Lua userdata bing opaque to Lua
scripts is what makes it easy to nicely integrate any low level
mechanism or paradigm into Lua, even though it makes their
serialization impossible (but not all objects hidden behind a userdata
are naturally serializable anyway).

Agreed, but maybe there's a way that we can combine Sam Roberts' suggestion, to have a socket relinquish its ownership and gaining access to an opaque identifier that is easily serializable (i.e. a number). Note that I'm not mentioning file descriptors. That identifier could be the fd but one must not rely on that. Only that I could get that identifier, send it to another lua_State and reconstruct a socket object from it and resume processing there.

Maybe something like
local raw = my_socket:detach()

==> send raw to another VM and there

local new_socket = socket.tcp(raw)
new_socket:read -- etc etc

Anyway, this, if it gets considered, will become part of LuaSocket 3 :)