Change. socket:setfd() set `fd` to invalid value.
This is alternative to acceptfd method.
Change. socket:setfd() set fd to invalid value.
Change. socket:setfd return previews fd value.
Change. socket.tcp and socket.udp can create object based on fd.
Add. test setfd
---- server.lua
cli = assert(srv:accept())
-- test if worker thread take ownership and clear `fd`
if run_worker_thread(cli:getfd()) then cli:setfd() end
cli:close()
---- worker.lua
-- wrap raw `fd` to socket object
local sock = socket.tcp(..., "client")
-- do work with sock object
This change no longer lines up with master, and it's not obvious to me that it should be made to. Can it be either resolved or closed?
Not sure what this was trying to solve.
The main idea for this PR is allow to pass socket to the separate LuaVM (e.g. in separate os thread) and create clien socket in there.
So in the main LuaVM called server:accept then file descriptor pass to the separate LuaVM.
In this case it is important that in the main LuaVM GC should not close this socket if it passes to separate thread.
@moteus I think this is a useful change. I know this has been open like forever, but would you mind rebasing it on master and add the documentation changes?
I think that adding a string as option to these functions will prevent future extensions, if there are any. Should there be an options table instead?