luasocket icon indicating copy to clipboard operation
luasocket copied to clipboard

Change. socket:setfd() set `fd` to invalid value.

Open moteus opened this issue 12 years ago • 5 comments

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

moteus avatar Jun 11 '13 11:06 moteus

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?

ewestbrook avatar Mar 11 '19 02:03 ewestbrook

Not sure what this was trying to solve.

diegonehab avatar Mar 11 '19 03:03 diegonehab

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 avatar Mar 19 '19 08:03 moteus

@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?

Tieske avatar Mar 22 '22 17:03 Tieske

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?

diegonehab avatar Mar 22 '22 17:03 diegonehab