lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great Andrew Starks once stated:
> 
> poll/select
> A "poll" or "select" library that used the native environment's
> best-equivelent. I know that this is hard, but if one is trying to
> achieve the ability to catch file / socket i/o, there should be a
> library that other library authors use. LuaSocket does this (as well
> as sleep), and even makes it easy to integrate with other libraries.
> But it is not insignificant that I need to load LuaSocket to use it
> and it only supports select on Windows. IO Completion ports would be
> much better.

  I have a specific module that wraps select() [1] (very old systems,
possibly Windows)/poll() (there rest of the POSIX universe)/epoll() (Linux
only), depending upon the support.  The Lua visible API is the same, but it
does expose some additional functionality if it exists (epoll() does both
level and edge triggered events for instance).  It works for Unix systems; I
do not have a Windows system for testing.

  One downside, it requires file handles (ints), not FILE objects.  I needed
this primarily to work with sockets (another module I have [2]) so to avoid
polluting my select module with implementation details of that, I decided to
punt and leave it with file handles.  

  IO Completion ports only exist on Windows---they use a different model of
programming than Posix, and sometimes, the two have a hard time meshing (for
portability).

  -spc

[1]	https://github.com/spc476/lua-conmanorg/blob/master/src/pollset.c

[2]	https://github.com/spc476/lua-conmanorg/blob/master/src/net.c