Re: Example using ffi to wrap poll or epoll.

  • From: Justin Cormack <justin@xxxxxxxxxxxxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Tue, 30 Oct 2012 22:35:04 +0000

On Tue, Oct 30, 2012 at 9:02 PM, Tim Caswell <tim@xxxxxxxxxxxxxx> wrote:
> I've seen Mike mention several times on this list that we shouldn't be
> using callback event loops (like libuv or libev), especially if we
> don't need cross-platform compatibility.  The only reason I use libuv
> for everything is I don't know any better.
>
> So my question is how do I create a tcp server without these
> libraries?  Is there some example out there that shows how to
> multiplex file I/O, timers, and network events.
>
> I'm fine if it's linux only, that's about the only platform I develop
> and deploy to (I develop on a linux VM using c9.io from my browser)

Everything you might need except decent examples is in ljsyscall
https://github.com/justincormack/ljsyscall there is a trivial example
without timers in the epoll example here
https://github.com/justincormack/ljsyscall-examples and there are all
the parts like timers in the test suite for ljsyscall, but not put
together. Basically you are best off using timerfd which gives timer
events to file descriptors along with epoll for network events.

Under Linux what you do for file events is less clear. Async IO does
not really exist (well, thats not 100% true), so you either block or
thread or various other things, there are no good solutions.

Justin

Other related posts: