lua-users home
lua-l archive

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


On 01/07/15 11:43, Sean Conner wrote:
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 [1] as Linux does some aggressive memory caching. select() [2]
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
expected.

Errrr, yes, that was I said, I need to read from device files. Yes, I know select() works on them. I only was trying to use luasocket's select() for that.


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.

Yes, I gather that. But, luasocket allegedly allows to feed an arbitrary fd to a socket object, and is supposed to work when done that [1] . It's just that didn't find anyone doing that, and it seems a critical piece is missing (the fileno).

What I'm doing is a I/O driven single-thread concurrent application, that must process data coming from sockets and from device files (serials, mouse, etc.) IT already works when using nixio as library, which allows to handle sockets and files as equals, but now I was trying to do the same on pure luasocket.

Jorge

[1] http://lua-users.org/lists/lua-l/2006-10/msg00125.html