Comments (4)
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.
ok, thank you, I'll follow your progress. :)
from nixio.
can wrap this nixio socket object to a light userdata, and pass to another thread, like your lua-zmq-threads?
from nixio.
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)
- A method for geting clock time is wanted HOT 1
- luarocks install nixio fails
- new rockspec version 0.3.2 and into luarocks repo? HOT 3
- installing on Debian/jessy fails with compiler warning HOT 4
- build failures with gcc5+? HOT 1
- Build failure on OSX 10.11 HOT 1
- Reading from standard input?
- build failures with openssl 3.0
- lstat patch (fs.c) HOT 1
- Build Fails on Mac OSX Lion HOT 5
- compile failure on fedora 19 HOT 3
- nixio.bit.check is meant to accept multiple flags but doesn't
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nixio.