Giter Site home page Giter Site logo

Comments (4)

Neopallium avatar Neopallium commented on August 29, 2024

Simple answer: There is no support for this.

Longer answer:
Nixio doesn't have support for creating a Socket from an FD number. Even if it did both threads would have an object that would try to close the FD when the object is GCed by Lua. So you would have to have a way to reference count the object or delegate which thread owns the FD and only have that thread close it on GC.

If you still want to try using sendfile from a thread then you could create a very simple C module that only wraps the sendfile() function. That function would take the in/out FD as numbers instead of objects. This would be a quick way to test if this design will work for you.

There may also be some issues with lua-handlers when trying to write to the socket from another thread. Write timeout, flushing the internal connection write buffer.

I think the best way to scale would be to use nodejs's cluster design where the server forks multiple child worker processes that have shared access to the listening sockets.

I am working on a new design for lua-handlers that supports different backends for IO/events:
https://github.com/Neopallium/lua-handlers/tree/poller

I am trying to replace nixio with a new module lua-llnet:
https://github.com/Neopallium/lua-llnet

lua-llnet has much better performance under LuaJIT since it uses the FFI interface. I am planning on adding support for sending an FD over a Unix Domain socket (this is needed to support nodejs's clustering design), this feature could be used for passing a socket to another thread.

There are still a few missing features (timers/signal fd support with the epoll backend, and TLS sockets) before I release the new lua-handlers design.

from nixio.

miketang84 avatar miketang84 commented on August 29, 2024

ok, thank you, I'll follow your progress. :)

from nixio.

miketang84 avatar miketang84 commented on August 29, 2024

can wrap this nixio socket object to a light userdata, and pass to another thread, like your lua-zmq-threads?

from nixio.

Neopallium avatar Neopallium commented on August 29, 2024

no. The zeromq context is designed to be shared between threads. The nixio socket objects are just wrappers for the socket FD. You will run into problems with the GC like I outlined in my previous comment.

from nixio.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.