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

Unable to send handles with uv_write2 #692

Open
nikneym opened this issue Feb 16, 2024 · 0 comments
Open

Unable to send handles with uv_write2 #692

nikneym opened this issue Feb 16, 2024 · 0 comments

Comments

@nikneym
Copy link

nikneym commented Feb 16, 2024

Hi, I'm trying to send handles over pipes. I've created a socketpair and sent one end to a new thread and when I try to read/write between them, it just works. In the following code though, I'm sending accepted TCP connections to a thread via write2 but it doesn't work.

local uv = require "luv"

local fds = uv.socketpair(nil, nil, { nonblock = true }, { nonblock = true })

-- setup worker thread
uv.new_thread(function(fd)
  local uv = require "luv"

  local pipe = uv.new_pipe(false)
  pipe:open(fd)

  pipe:listen(128, function()
    local client = uv.new_tcp()
    pipe:accept(client)

    print "handle received by worker"
    client:close()
  end)

  uv.run()
end, fds[2])

-- setup writer pipe & tcp server
local pipe = uv.new_pipe(true)
pipe:open(fds[1])

local server = uv.new_tcp()
server:bind("127.0.0.1", 3000)

server:listen(128, function()
  local client = uv.new_tcp()
  server:accept(client)

  -- send it to worker thread
  pipe:write2("", client)
end)

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

No branches or pull requests

1 participant