[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Sharing data between LuaTask tasks...
- From: duck <duck@...>
- Date: Sat, 19 May 2007 04:31:02 +0000
> But in the LuaSocket case... these object has two methods to manipulate
> the underlying native machinery: setfd and getfd.
> You can get the native socket with getfd and pass it as an integer value.
> If you use skt:setfd( -1 ) the native socket is not closed when skt is
> garbage collected.
>
> You can download a little old examples using this trick at:
> http://www.soongsoft.com/lua/LuaTaskExamples.tar.gz
This is rather cool. I see that you do a bind-listen-close, then switch
the socket's fd, then call accept to get a new "tcp{client}" class socket
with which you can communicate.
I presume the initial bind-listen-close is only there to switch the
cloned socket's class ID to "tcp{server}" so that it will be legal to
LuaSocket when passed to accept()?
If I wanted to call accept() outside the child task and to clone the already-
accept()ed socket inside the child, I guess I'd have to trick LuaSocket into
providing me with a "tcp{client}" class socket into which I could stuff
the accept()ed socket's fd? And the only way I can see to do that is via
a successful connect() or accept()...in other words, it's not really possible.
In your examples, you mention:
-- I hacked LuaSocket to simplify this but,
-- in order to use a stock distribution of LuaSocket,
-- I'm going to use code based in a kind suggestion
-- from Diego Nehab.
Any chance of posting the patches you wrote here so I can have a look at
them? I don't mind the bind-listen-close trick but it would be nice to
avoid having to open listneing sockets unnecessarily. Wiould help to avoid
endpoint firewall nuisances and complaints from admins about "large amounts
of socket activity on your PC" :-)
I thought of simply adding a function to tcp.c called, say, "setclass()"
which would take a master socket and blindly change its class. I can't see
any way to tweak the metatable of a userdata from inside Lua -- and I
suspect that there isn't one (and that this is deliberate to prevent
disasters).