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 Jorge once stated:
> On 18/10/12 02:05, William Ahern wrote:
> >You can't poll on _regular_ files. It's actually a POSIX requirement that
> >regular files always signal immediate readiness for reading and writing.
> >Historically, block I/O devices were considered sufficiently fast in the
> >grand scheme of things that it was useless to poll on them. And it's also
> >really hard to implement in kernels--few (I can't think of any) do it
> >without relying on threads.
> >
> >Character devices, named fifos, unix domain sockets... these things are not
> >regular files.
> 
> Perfectly clear and reasonable.
> 
> Then it comes another question: what happens when i open a, say, 
> character device file with Lua's io.open()? What happens to it's fd? 

  Lua's io.open() is just a wrapper around fopen() (the ANSI C library
function).  Under Unix, fopen() eventually calls open(), which returns a
file descriptor (fd).  ANSI C's FILE structure under Unix will contain a
copy of this descriptor, which can be obtained via the fileno() function
(not an ANSI C function).  

> I suppose it's still not pollable (i remember getting busy waits when
> opening files with the wrong sync mode flag in nixio).

  A character device is not a regular file, so it should be pollable using
select(), poll(), epoll(), kqueue(), etc (select() will be on every Unix
system; poll() on modern Unix systems; epoll() only on Linux; kqueue() on
BSD).

  -spc