lua-users home
lua-l archive

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


On 19 September 2014 17:18, Rena <hyperhacker@gmail.com> wrote:
The way I dealt with threading+sockets in one case was to modify
LuaSocket to expose the `fd` field of the socket objects and to add a
`socket.fromfd()` function. Then you can pass the fd (an integer) from
one thread to another, and the receiving thread can create its own
socket object.

A better choice (architecturally) is to use SCM_RIGHTS (on linux) to pass the file descriptor from one process to another.
Sadly, I don't know of any good integrations with luasocket or lanes on this front.
In fact, the only lua related SCM_RIGHTS code around I know of is undocumented inside of ljsyscall:
https://github.com/justincormack/ljsyscall/blob/358b49c16f31cbbe8bf43d4fcf96217144e3aa04/syscall/types.lua#L383