[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: luasocket and selecting from files.
- From: Sean Conner <sean@...>
- Date: Tue, 30 Jun 2015 22:29:08 -0400
It was thus said that the Great Jorge once stated:
> Hi everyone,
>
> I'm trying to use luasocket's select() to read from files, under Linux.
From files, like '/usr/local/include/lua.h' or from any type of device
that uses a file handle? I only ask this because using select() on an
actual file (like '/usr/local/include/lua.h') will *always* be readable and
writable---i.e. there's just no use in using select() for files [1] as Linux
does some aggressive memory caching.
select() [2] works much better for sockets and character devices like
/dev/tty.
> As far as can see, it is possible now trough judicious use of setfd()
> (and dirty()?). But I do not see where i can get that fd from (io.* uses
> a opaque thing for files).
To get the underlying file descriptor from a FILE *, you need to use the C
function fileno().
> Is there any working code out there doing this?
For files? I don't know, but it would be similar with files (as sockets
are file handles).
-spc
[1] I think this is even true for network file sytems like NFS but I
don't have a way to experiment with this right now.
[2] If you are using Linux, epoll() is a much better API for this type
of thing.