[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: luasocket and selecting from files.
- From: Sean Conner <sean@...>
- Date: Wed, 1 Jul 2015 05:43:17 -0400
It was thus said that the Great Jorge once stated:
> On 01/07/15 04:29, Sean Conner wrote:
> >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  as Linux does some aggressive memory caching. select() 
> >works much better for sockets and character devices like /dev/tty.
> Yes, is for device files that block reads when there is no data. And for
> plain files too.
Using select() on a real file (like "/usr/include/stdio.h") will *always*
*always* *always* return ready for both *reading and writing*. There's no
real point to using select() on a real file because of that behavior. Even
if you give select() an infinite timeout, it will *always* return ready if
you give it a file descriptor to a real file.
For character devices (like "/dev/tty") and sockets, select() works as
> >>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).
> I was thinking code preparing a file handle for serving with luasocket.
> There seems to be some weird dancing involved with creating a connected
> socket, replacing its fd, then invalidating something setting a fd of
> -1, etc.
The problem you are having is that luasocket was written to deal with
sockets, not files. You are trying to force it to so something it was not
written to deal with. If, perhaps, you describe what you are trying to
accomplish, someone can point you in a better direction.