Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

moteus
Copy link
Contributor

@moteus moteus commented Jun 11, 2013

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

diegonehab and others added 3 commits April 12, 2012 14:57
Change. socket:setfd return previews `fd` value.
Change. socket.tcp and socket.udp can create object based on `fd`.

Add. test setfd
```lua
  ---- server
  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
  -- wrap raw `fd` to socket object
  local sock = socket.tcp(..., "client")
  -- do work with sock object
```
@ewestbrook
Copy link
Contributor

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?

@diegonehab
Copy link
Contributor

Not sure what this was trying to solve.

@moteus
Copy link
Contributor Author

moteus commented Mar 19, 2019

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.

@Tieske
Copy link
Member

Tieske commented Mar 22, 2022

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

@diegonehab
Copy link
Contributor

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?

tcp->sock = (t_socket) luaL_checknumber(L, 2);
return 0;
t_socket fd = tcp->sock;
if(lua_gettop(L) == 1) tcp->sock = SOCKET_INVALID;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than gettop I think you'd want a lua_isnoneornil check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants