[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Sharing data between LuaTask tasks...
- From: Daniel Quintela <dq@...>
- Date: Mon, 14 May 2007 11:37:27 -0300
duck escribió:
It occurred to me that LuaTask (in which each LuaTask gets its own Lua
state in a new thread) might be a handy way of writing simple threaded
servers. However, only number and string objects can be passed in messages
between tasks.
I was wondering:
1. Is there any reliable way to pass an accept()ed LuaSocket object from
one LuaTask to another? Can userdata be serialised?
2. If so (and assuming that socket is only ever manipulated in the task to
which it's passed), is it safe to pass this sort of data between tasks? Is
LuaSocket itself thread-safe?
Has anyone used LuaTask for handling multiple threads which communicate
using multiple blocking sockets?
There is no general answer about passing userdata.
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
Best regards,
Daniel